MCPcopy Create free account
hub / github.com/RUC-NLPIR/WebThinker / unsafe_execute

Function unsafe_execute

scripts/lcb_runner/evaluation/utils_execute.py:87–117  ·  view source on GitHub ↗
(check_program, result, timeout)

Source from the content-addressed store, hash-verified

85
86
87def unsafe_execute(check_program, result, timeout):
88
89 with create_tempdir():
90
91 # These system calls are needed when cleaning up tempdir.
92 import os
93 import shutil
94
95 rmtree = shutil.rmtree
96 rmdir = os.rmdir
97 chdir = os.chdir
98
99 # Disable functionalities that can make destructive changes to the test.
100 reliability_guard()
101
102 # Run program.
103 try:
104 exec_globals = {}
105 with swallow_io():
106 with time_limit(timeout):
107 exec(check_program, exec_globals)
108 result.append("passed")
109 except TimeoutException:
110 result.append("timed out")
111 except BaseException as e:
112 result.append(f"failed: {e}")
113
114 # Needed for cleaning up.
115 shutil.rmtree = rmtree
116 os.rmdir = rmdir
117 os.chdir = chdir
118
119
120@contextlib.contextmanager

Callers

nothing calls this directly

Calls 4

create_tempdirFunction · 0.85
swallow_ioFunction · 0.85
time_limitFunction · 0.85
reliability_guardFunction · 0.70

Tested by

no test coverage detected