-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexecuter_inner_parent.py
61 lines (50 loc) · 2.23 KB
/
executer_inner_parent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import json
import subprocess as sp
import time
try:
tmp_path = os.environ["TMPDIR"]
except:
tmp_path = "executer_temp_files"
class ExecuterInnerWrapper():
def __init__(self, core_id):
self.core_id = core_id
# Executes code with given inputs. Executes all inputs.
def execute_inner(self, code, inpu):
if not os.path.exists(tmp_path):
os.mkdir(tmp_path)
with open(f"{tmp_path}/INNER_CODE_INPUT_{str(self.core_id)}.json", "w+") as o:
json.dump({"code": code, "input": inpu}, o, indent=2)
deadp = sp.run(["python3", f"executer_inner_child.py", str(self.core_id)], capture_output=True)
print(deadp)
if deadp.returncode == 0:
data = None
try:
with open(f"{tmp_path}/INNER_LINES_OUTPUT_{str(self.core_id)}.json", "r") as r:
data = json.load(r)
o.close()
except Exception as E:
print(E)
return None, None, "cppyy core dump error", None
return data["lines"], data["output"], data["warning"], data["executed_code"]
else:
print(deadp)
return None, None, "cppyy core dump error", None
def main():
executer_inner = ExecuterInnerWrapper(100)
# return de line executions, the output, any warnings on the execution
# and the actual code executed, which migh be slightly diferent (but equivalent)
# to the one queried. The line numbers in the line per line log refer to this
# modified code
lines, out, warn, code = executer_inner.execute_inner( "int* fun_name(int var0iable, int* var1iable){\n"+
" while (var0iable < 10) {\n"+
" var0iable++;\n"+
" }\n"+
" var1iable[0] = var0iable;\n"+
" return var1iable;\n"+
"}", \
["1", "{1}"])
print(lines, out, warn)
print(code)
if __name__ == "__main__":
main()