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

Commit

Permalink
Update Status.UE
Browse files Browse the repository at this point in the history
  • Loading branch information
wxh06 committed Aug 5, 2020
1 parent c816998 commit f2ba5c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
33 changes: 20 additions & 13 deletions dockerjudge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,29 @@ def judge_test_cases(container, processor, tests, config):
'Judge test cases'
with ThreadPoolExecutor(max_workers=config.get('threads')) as executor:
futures = []
for i, test in zip(range(1, len(tests) + 1), tests):
for i, test in zip(range(len(tests)), tests):
futures.append(
executor.submit(test_case.__init__,
container, processor, i, test, config)
container, processor, i + 1, test, config)
)
futures[-1].add_done_callback(done_callback)
return [future.result()[2] for future in futures]


def done_callback(future):
'Callback'
result = future.result()
try:
result[0]['callback'].get('judge')(result[1], *result[2])
except TypeError:
pass
futures[-1].add_done_callback(done_callback(i, config))
return [
future.result()
if not future.exception() else (Status.UE, (None, None), .0)
for future in futures
]


def done_callback(i, config):
'Return the callback func for concurrent.futures.Future.add_done_callback'
def _done_callback(future):
result = ((Status.UE, (None, None), .0)
if future.exception() else future.result())
try:
config['callback'].get('judge')(i, *result)
except TypeError:
pass
return _done_callback


def run(container, processor, source, tests, config=None):
Expand Down
13 changes: 5 additions & 8 deletions dockerjudge/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@

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


def _get_io_file_path(ioro, processor, i, config):
Expand Down

0 comments on commit f2ba5c8

Please sign in to comment.