Skip to content

Commit 3d93e7e

Browse files
committed
Job cleaner, use own thread pool for graph traversal
#167 (comment)
1 parent 8d4e9fd commit 3d93e7e

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

sisyphus/graph.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def get_unfinished_jobs(job):
488488
self.for_all_nodes(get_unfinished_jobs, nodes=nodes)
489489
return states
490490

491-
def for_all_nodes(self, f, nodes=None, bottom_up=False):
491+
def for_all_nodes(self, f, nodes=None, bottom_up=False, *, pool: Optional[ThreadPool] = None):
492492
"""
493493
Run function f for each node and ancestor for `nodes` from top down,
494494
stop expanding tree branch if functions returns False. Does not stop on None to allow functions with no
@@ -497,6 +497,7 @@ def for_all_nodes(self, f, nodes=None, bottom_up=False):
497497
:param (Job)->bool f: function will be executed for all nodes
498498
:param nodes: all nodes that will be checked, defaults to all output nodes in graph
499499
:param bool bottom_up: start with deepest nodes first, ignore return value of f
500+
:param pool: use custom thread pool
500501
:return: set with all visited nodes
501502
"""
502503

@@ -544,7 +545,8 @@ def for_all_nodes(self, f, nodes=None, bottom_up=False):
544545

545546
pool_lock = threading.Lock()
546547
finished_lock = threading.Lock()
547-
pool = self.pool
548+
if not pool:
549+
pool = self.pool
548550

549551
# recursive function to run through tree
550552
def runner(job):

sisyphus/manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def f(job):
3838
return True
3939

4040
while not self.stopped:
41-
self.sis_graph.for_all_nodes(f)
41+
self.sis_graph.for_all_nodes(f, pool=self.thread_pool)
4242
time.sleep(gs.JOB_CLEANER_INTERVAL)
4343

4444
def close(self):

0 commit comments

Comments
 (0)