def judge(self, sandbox, package):
loop = get_event_loop()
executable = await package.install(sandbox)
stdin_file = path.join(sandbox.in_dir, 'stdin')
mkfifo(stdin_file)
stdout_file = path.join(sandbox.in_dir, 'stdout')
mkfifo(stdout_file)
stderr_file = path.join(sandbox.in_dir, 'stderr')
mkfifo(stderr_file)
with socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK) as cgroup_sock:
cgroup_sock.bind(path.join(sandbox.in_dir, 'cgroup'))
cgroup_sock.listen()
execute_task = loop.create_task(executable.execute(
sandbox,
stdin_file='/in/stdin',
stdout_file='/in/stdout',
stderr_file='/in/stderr',
cgroup_file='/in/cgroup'))
others_task = gather(
loop.run_in_executor(None, self.do_stdin, stdin_file),
loop.run_in_executor(None, self.do_stdout, stdout_file),
read_pipe(stderr_file, MAX_STDERR_SIZE),
wait_cgroup(cgroup_sock,
execute_task,
self.time_limit_ns,
self.memory_limit_bytes,
self.process_limit))
execute_status = await execute_task
_, correct, stderr, (time_usage_ns, memory_usage_bytes) = \
await others_task
if memory_usage_bytes >= self.memory_limit_bytes:
status = STATUS_MEMORY_LIMIT_EXCEEDED
score = 0
elif time_usage_ns >= self.time_limit_ns:
status = STATUS_TIME_LIMIT_EXCEEDED
score = 0
elif execute_status:
status = STATUS_RUNTIME_ERROR
score = 0
elif not correct:
status = STATUS_WRONG_ANSWER
score = 0
else:
status = STATUS_ACCEPTED
score = self.score
return status, score, time_usage_ns, memory_usage_bytes, stderr
评论列表
文章目录