-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunner.py
60 lines (53 loc) · 1.8 KB
/
runner.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
import os
import shlex
import judgercore
from config import RUN_USER_UID, RUN_GROUP_GID
class Runner(object):
@staticmethod
def run(
working_path,
exe_name,
in_name,
out_name,
run_config,
limit_config,
spj={},
):
command = run_config['command'].format(exe_path=working_path /
exe_name,
**spj)
command = shlex.split(command)
runner_in = working_path / in_name
runner_out = working_path / out_name
log_path = working_path / 'runner.log'
os.chown(working_path, RUN_USER_UID, RUN_GROUP_GID)
env = ['PATH=' + os.environ.get('PATH', '')] + run_config.get(
'env', [])
seccomp_rule = run_config['seccomp_rule']
run_result = judgercore.run(
max_cpu_time=limit_config['max_cpu_time'],
max_real_time=limit_config['max_cpu_time'] * 3,
max_memory=limit_config['max_memory'],
max_stack=128 * 1024 * 1024,
max_output_size=32 * 1024 * 1024,
max_process_number=judgercore.UNLIMITED,
exe_path=command[0],
input_path=str(runner_in),
output_path=str(runner_out),
error_path=str(runner_out),
args=command[1::],
env=env,
log_path=str(log_path),
seccomp_rule_name=seccomp_rule,
uid=RUN_USER_UID,
gid=RUN_GROUP_GID)
return run_result
#
#
# if __name__ == '__main__':
# from languages import cpp_lang_config
#
# a = Runner()
# limit = {"max_cpu_time": 2000, "max_memory": 5 * 1024 * 1024}
# c = a.run(Path("/judger/test1"), "main", "test1.in", "test1.out", cpp_lang_config["run"], limit)
# print(c)