diff --git a/dockerjudge/__init__.py b/dockerjudge/__init__.py index c7dae5d..9dbe119 100644 --- a/dockerjudge/__init__.py +++ b/dockerjudge/__init__.py @@ -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): diff --git a/dockerjudge/test_case.py b/dockerjudge/test_case.py index a15c8b5..1c3d6dd 100644 --- a/dockerjudge/test_case.py +++ b/dockerjudge/test_case.py @@ -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):