diff --git a/nemo_skills/code_execution/local_sandbox/local_sandbox_server.py b/nemo_skills/code_execution/local_sandbox/local_sandbox_server.py index 4f5fa570cd..d6ae4283e6 100644 --- a/nemo_skills/code_execution/local_sandbox/local_sandbox_server.py +++ b/nemo_skills/code_execution/local_sandbox/local_sandbox_server.py @@ -101,6 +101,11 @@ def __init__(self, family=-1, type=-1, proto=-1, fileno=None): socket_module.socket = BlockedSocket # Blocks: import socket; socket.socket() shell = TerminalInteractiveShell() + # TerminalInteractiveShell installs a SIGINT handler that calls sys.exit(0) + # instead of raising KeyboardInterrupt when _executing is False (which is + # the case when run_cell is called programmatically). Restore the default + # handler so SIGINT raises KeyboardInterrupt and our except clause catches it. + signal.signal(signal.SIGINT, signal.SIG_DFL) try: while True: try: @@ -203,7 +208,7 @@ def stop_shell(self, shell_id): proc.terminate() proc.join(timeout=2.0) - def run_cell(self, shell_id, code, timeout=1.0, grace=0.5, traceback_verbosity="Plain"): + def run_cell(self, shell_id, code, timeout=1.0, grace=2.0, traceback_verbosity="Plain"): """ Execute `code` on shell `shell_id`. - timeout: seconds to wait for normal completion @@ -427,7 +432,7 @@ def execute_ipython_session(generated_code, session_id, timeout=30, traceback_ve # Execute code using ShellManager with proper timeout and cancellation result = shell_manager.run_cell( - session_id, generated_code, timeout=timeout, grace=0.5, traceback_verbosity=traceback_verbosity + session_id, generated_code, timeout=timeout, grace=2.0, traceback_verbosity=traceback_verbosity ) # Determine if this is effectively a new session