From af2f2854e2139d4d5c7b47140297188c025d4131 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Mon, 18 Mar 2024 14:18:07 +0800 Subject: [PATCH] Reset alarm signal when the function is ended Fixes #29690 --- src/transformers/dynamic_module_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/transformers/dynamic_module_utils.py b/src/transformers/dynamic_module_utils.py index 72fd0367a0f401..a89105029868a1 100644 --- a/src/transformers/dynamic_module_utils.py +++ b/src/transformers/dynamic_module_utils.py @@ -592,8 +592,9 @@ def resolve_trust_remote_code(trust_remote_code, model_name, has_local_code, has if has_local_code: trust_remote_code = False elif has_remote_code and TIME_OUT_REMOTE_CODE > 0: + prev_sig_handler = None try: - signal.signal(signal.SIGALRM, _raise_timeout_error) + prev_sig_handler = signal.signal(signal.SIGALRM, _raise_timeout_error) signal.alarm(TIME_OUT_REMOTE_CODE) while trust_remote_code is None: answer = input( @@ -614,6 +615,10 @@ def resolve_trust_remote_code(trust_remote_code, model_name, has_local_code, has f"load the model. You can inspect the repository content at https://hf.co/{model_name}.\n" f"Please pass the argument `trust_remote_code=True` to allow custom code to be run." ) + finally: + if prev_sig_handler is not None: + signal.signal(signal.SIGALRM, prev_sig_handler) + signal.alarm(0) elif has_remote_code: # For the CI which puts the timeout at 0 _raise_timeout_error(None, None)