Skip to content
This repository was archived by the owner on Jul 22, 2022. It is now read-only.

Commit f2ba5c8

Browse files
committed
Update Status.UE
1 parent c816998 commit f2ba5c8

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

dockerjudge/__init__.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,29 @@ def judge_test_cases(container, processor, tests, config):
118118
'Judge test cases'
119119
with ThreadPoolExecutor(max_workers=config.get('threads')) as executor:
120120
futures = []
121-
for i, test in zip(range(1, len(tests) + 1), tests):
121+
for i, test in zip(range(len(tests)), tests):
122122
futures.append(
123123
executor.submit(test_case.__init__,
124-
container, processor, i, test, config)
124+
container, processor, i + 1, test, config)
125125
)
126-
futures[-1].add_done_callback(done_callback)
127-
return [future.result()[2] for future in futures]
128-
129-
130-
def done_callback(future):
131-
'Callback'
132-
result = future.result()
133-
try:
134-
result[0]['callback'].get('judge')(result[1], *result[2])
135-
except TypeError:
136-
pass
126+
futures[-1].add_done_callback(done_callback(i, config))
127+
return [
128+
future.result()
129+
if not future.exception() else (Status.UE, (None, None), .0)
130+
for future in futures
131+
]
132+
133+
134+
def done_callback(i, config):
135+
'Return the callback func for concurrent.futures.Future.add_done_callback'
136+
def _done_callback(future):
137+
result = ((Status.UE, (None, None), .0)
138+
if future.exception() else future.result())
139+
try:
140+
config['callback'].get('judge')(i, *result)
141+
except TypeError:
142+
pass
143+
return _done_callback
137144

138145

139146
def run(container, processor, source, tests, config=None):

dockerjudge/test_case.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212

1313
def __init__(container, processor, i, ioput, config):
1414
'Copy binary files to `i` and judge'
15-
try:
16-
container.exec_run(f'cp -r 0 {i}', workdir=str(processor.workdir))
17-
exec_run(container, processor.before_judge, f'{processor.workdir}/{i}')
18-
res = judge(container, processor, i, ioput, config)
19-
exec_run(container, processor.after_judge, f'{processor.workdir}/{i}')
20-
return config, i - 1, res
21-
except Exception: # pylint: disable = broad-except
22-
return config, i - 1, [Status.UE, (None, None), .0]
15+
container.exec_run(f'cp -r 0 {i}', workdir=str(processor.workdir))
16+
exec_run(container, processor.before_judge, f'{processor.workdir}/{i}')
17+
res = judge(container, processor, i, ioput, config)
18+
exec_run(container, processor.after_judge, f'{processor.workdir}/{i}')
19+
return res
2320

2421

2522
def _get_io_file_path(ioro, processor, i, config):

0 commit comments

Comments
 (0)