Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyene committed Dec 25, 2023
1 parent 010396c commit 0bda201
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions dmoj/judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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]:
Expand Down

0 comments on commit 0bda201

Please sign in to comment.