From 0bda2018124033abeb23053c1e9c77f2ad89cbcc Mon Sep 17 00:00:00 2001 From: Tudor Brindus Date: Mon, 25 Dec 2023 18:00:05 -0500 Subject: [PATCH] wip --- dmoj/judge.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/dmoj/judge.py b/dmoj/judge.py index 5b4b09141..9d145aafd 100644 --- a/dmoj/judge.py +++ b/dmoj/judge.py @@ -143,9 +143,12 @@ def _grading_thread_main(self, ipc_ready_signal: threading.Event, report) -> Non assert self.current_judge_worker is not None try: + worker_tempdir = None + def _ipc_hello(_report, tempdir: str): + nonlocal worker_tempdir ipc_ready_signal.set() - tempfile.tempdir = tempdir + worker_tempdir = tempdir ipc_handler_dispatch: Dict[IPC, Callable] = { IPC.HELLO: _ipc_hello, @@ -181,6 +184,14 @@ def _ipc_hello(_report, tempdir: str): self.current_judge_worker.wait_with_timeout() self.current_judge_worker = None + print('cleaning up', worker_tempdir) + os.system('ls -al %s' % worker_tempdir) + if worker_tempdir: + try: + shutil.rmtree(worker_tempdir) + except: # noqa: E722 + pass + # Might not have been set if an exception was encountered before HELLO message, so signal here to keep the # other side from waiting forever. ipc_ready_signal.set() @@ -430,20 +441,6 @@ def _report_unhandled_exception() -> None: if ipc_recv_thread.is_alive(): logger.error('Judge IPC recv thread is still alive after timeout, shutting worker down anyway!') - try: - shutil.rmtree(tempdir) - except: # noqa: E722 - pass - - # FIXME(tbrindus): we need to do this because cleaning up temporary directories happens on __del__, which - # won't get called if we exit the process right now (so we'd leak all files created by the grader). This - # should be refactored to have an explicit `cleanup()` or similar, rather than relying on refcounting - # working out. - from dmoj.executors.compiled_executor import _CompiledExecutorMeta - - for cached_executor in _CompiledExecutorMeta.compiled_binary_cache.values(): - cached_executor.is_cached = False - cached_executor.cleanup() self.grader = None def _grade_cases(self) -> Generator[Tuple[IPC, tuple], None, None]: