Skip to content

Commit

Permalink
JobCleaner, properly stops threads at close
Browse files Browse the repository at this point in the history
Partly fixes #164
  • Loading branch information
albertz committed Dec 16, 2024
1 parent a0319f3 commit 42f6ab2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions sisyphus/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down

0 comments on commit 42f6ab2

Please sign in to comment.