MCPcopy Index your code
hub / github.com/evalplus/evalplus / unsafe_execute

Function unsafe_execute

tools/_experimental/evaluate_runtime.py:22–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20 code: str, inputs: List, warmups: List, entry_point: str
21) -> Union[str, float]:
22 def unsafe_execute():
23 with create_tempdir():
24 # These system calls are needed when cleaning up tempdir.
25 import os
26 import shutil
27
28 rmtree = shutil.rmtree
29 rmdir = os.rmdir
30 chdir = os.chdir
31 # Disable functionalities that can make destructive changes to the test.
32 reliability_guard()
33 # load functions
34 exec_globals = {}
35 exec(code, exec_globals)
36 fn = exec_globals[entry_point]
37 try:
38 # warmup calls
39 for warmup in warmups:
40 with swallow_io():
41 fn(*warmup)
42
43 start_time = time.time()
44 # real call
45 with swallow_io():
46 with time_limit(3):
47 fn(*inputs)
48 duration = time.time() - start_time
49
50 result.append(duration)
51 except TimeoutException:
52 result.append("timed out")
53 except BaseException as e:
54 result.append("thrown exception")
55 # Needed for cleaning up.
56 shutil.rmtree = rmtree
57 os.rmdir = rmdir
58 os.chdir = chdir
59
60 manager = multiprocessing.Manager()
61 result = manager.list()

Callers

nothing calls this directly

Calls 4

create_tempdirFunction · 0.90
reliability_guardFunction · 0.90
swallow_ioFunction · 0.90
time_limitFunction · 0.90

Tested by

no test coverage detected