From a58c3dbe6cb9620624a16360b6624fcd23f2e7f9 Mon Sep 17 00:00:00 2001 From: helsonxiao Date: Thu, 4 Apr 2024 22:52:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B5=84=E6=BA=90=E6=B3=84=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/judge_client.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server/judge_client.py b/server/judge_client.py index ec94050..c58adb9 100644 --- a/server/judge_client.py +++ b/server/judge_client.py @@ -32,7 +32,6 @@ class JudgeClient(object): self._test_case_dir = test_case_dir self._submission_dir = submission_dir - self._pool = Pool(processes=psutil.cpu_count()) self._test_case_info = self._load_test_case_info() self._spj_version = spj_version @@ -46,6 +45,8 @@ class JudgeClient(object): if not os.path.exists(self._spj_exe): raise JudgeClientError("spj exe not found") + self._pool = Pool(processes=psutil.cpu_count()) + def _load_test_case_info(self): try: with open(os.path.join(self._test_case_dir, "info")) as f: @@ -179,10 +180,14 @@ class JudgeClient(object): def run(self): tmp_result = [] result = [] - for test_case_file_id, _ in self._test_case_info["test_cases"].items(): - tmp_result.append(self._pool.apply_async(_run, (self, test_case_file_id))) - self._pool.close() - self._pool.join() + try: + for test_case_file_id, _ in self._test_case_info["test_cases"].items(): + tmp_result.append(self._pool.apply_async(_run, (self, test_case_file_id))) + except Exception as e: + raise e + finally: + self._pool.close() + self._pool.join() for item in tmp_result: # exception will be raised, when get() is called # # http://stackoverflow.com/questions/22094852/how-to-catch-exceptions-in-workers-in-multiprocessing