From 5556b5be2a26576def67abe8587764a02f069de0 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Wed, 10 Jan 2024 14:05:07 +0100 Subject: [PATCH] Fix worker proc hanging at exception (#172) Not all exceptions in Task.run will lead to logging_thread.stop(), which is required that the proc does not hang at exit, because logging_thread was not a daemon thread. We make it a daemon thread now. And also, we additionally make extra sure that logging_thread.stop() is called. (Although there are maybe still other rare cases where this is not effective, so the daemon thread property is still important as well.) Fix #171. --- sisyphus/worker.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sisyphus/worker.py b/sisyphus/worker.py index 54e77b3..6fa51e3 100644 --- a/sisyphus/worker.py +++ b/sisyphus/worker.py @@ -57,7 +57,7 @@ def __init__(self, job, task, task_id): self.task = task self.task_id = task_id self.start_time = None - super().__init__() + super().__init__(daemon=True) self.out_of_memory = False self._cond = Condition() self.__stop = False @@ -248,5 +248,8 @@ def worker_helper(args): if hasattr(task._job, "_sis_environment") and task._job._sis_environment: task._job._sis_environment.modify_environment() - # run task - task.run(task_id, resume_job, logging_thread=logging_thread) + try: + # run task + task.run(task_id, resume_job, logging_thread=logging_thread) + finally: + logging_thread.stop()