MCPcopy Create free account
hub / github.com/OpenManus/OpenManus-RL / timeout

Function timeout

openmanus_rl/tools/python_code_generator/tool.py:27–53  ·  view source on GitHub ↗
(seconds)

Source from the content-addressed store, hash-verified

25# Custom context manager for code execution timeout
26@contextmanager
27def timeout(seconds):
28
29 if is_windows_os():
30 # Windows timeout using threading.Timer
31 def raise_timeout():
32 raise TimeoutException("Code execution timed out")
33 timer = threading.Timer(seconds, raise_timeout)
34 timer.start()
35 try:
36 yield
37 finally:
38 timer.cancel()
39
40 else:
41 def timeout_handler(signum, frame):
42 raise TimeoutException("Code execution timed out")
43
44 # Set the timeout handler
45 original_handler = signal.signal(signal.SIGALRM, timeout_handler)
46 signal.alarm(seconds)
47
48 try:
49 yield
50 finally:
51 # Restore the original handler and disable the alarm
52 signal.alarm(0)
53 signal.signal(signal.SIGALRM, original_handler)
54
55
56class Python_Code_Generator_Tool(BaseTool):

Callers 1

execute_code_snippetMethod · 0.85

Calls 1

is_windows_osFunction · 0.85

Tested by

no test coverage detected