MCPcopy Create free account
hub / github.com/huggingface/evaluate / unsafe_execute

Function unsafe_execute

metrics/code_eval/execute.py:56–86  ·  view source on GitHub ↗
(check_program, result, timeout)

Source from the content-addressed store, hash-verified

54
55
56def unsafe_execute(check_program, result, timeout):
57
58 with create_tempdir():
59
60 # These system calls are needed when cleaning up tempdir.
61 import os
62 import shutil
63
64 rmtree = shutil.rmtree
65 rmdir = os.rmdir
66 chdir = os.chdir
67
68 # Disable functionalities that can make destructive changes to the test.
69 reliability_guard()
70
71 # Run program.
72 try:
73 exec_globals = {}
74 with swallow_io():
75 with time_limit(timeout):
76 exec(check_program, exec_globals)
77 result.append("passed")
78 except TimeoutException:
79 result.append("timed out")
80 except BaseException as e:
81 result.append(f"failed: {e}")
82
83 # Needed for cleaning up.
84 shutil.rmtree = rmtree
85 os.rmdir = rmdir
86 os.chdir = chdir
87
88
89@contextlib.contextmanager

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…