From 42f6ab2bcd484e1c165371932500f40c2ef01384 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Mon, 16 Dec 2024 10:04:17 +0100 Subject: [PATCH] JobCleaner, properly stops threads at close Partly fixes #164 --- sisyphus/manager.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sisyphus/manager.py b/sisyphus/manager.py index f0e4137..93ebd9a 100644 --- a/sisyphus/manager.py +++ b/sisyphus/manager.py @@ -29,20 +29,23 @@ def __init__(self, sis_graph, worker=gs.JOB_CLEANER_WORKER): self.sis_graph = sis_graph self.worker = worker self.thread_pool = ThreadPool(self.worker) - self.stopped = False + self.stopped = threading.Event() def run(self): def f(job): + if self.stopped.is_set(): + return False if job._sis_cleanable(): self.thread_pool.apply_async(tools.default_handle_exception_interrupt_main_thread(job._sis_cleanup)) return True - while not self.stopped: + while not self.stopped.is_set(): self.sis_graph.for_all_nodes(f, pool=self.thread_pool) - time.sleep(gs.JOB_CLEANER_INTERVAL) + self.stopped.wait(gs.JOB_CLEANER_INTERVAL) def close(self): - self.stopped = True + self.stopped.set() + self.join() self.thread_pool.close()