Skip to content

Commit a3fe22b

Browse files
committed
refactor: pass executor to _load_tasks_parallel
This will make a subsequent commit that adds support for a ThreadPoolExecutor cleaner.
1 parent 6bf2abf commit a3fe22b

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/taskgraph/generator.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,13 @@ def _load_tasks_serial(self, kinds, kind_graph, parameters):
312312

313313
return all_tasks
314314

315-
def _load_tasks_parallel(self, kinds, kind_graph, parameters):
315+
def _load_tasks_parallel(self, kinds, kind_graph, parameters, executor):
316316
all_tasks = {}
317317
futures_to_kind = {}
318318
futures = set()
319319
edges = set(kind_graph.edges)
320320

321-
with ProcessPoolExecutor(
322-
mp_context=multiprocessing.get_context("fork")
323-
) as executor:
324-
321+
with executor:
325322
def submit_ready_kinds():
326323
"""Create the next batch of tasks for kinds without dependencies."""
327324
nonlocal kinds, edges, futures
@@ -456,7 +453,8 @@ def _run(self):
456453
if platform.system() != "Linux" or os.environ.get("TASKGRAPH_SERIAL"):
457454
all_tasks = self._load_tasks_serial(kinds, kind_graph, parameters)
458455
else:
459-
all_tasks = self._load_tasks_parallel(kinds, kind_graph, parameters)
456+
executor = ProcessPoolExecutor(mp_context=multiprocessing.get_context("fork"))
457+
all_tasks = self._load_tasks_parallel(kinds, kind_graph, parameters, executor)
460458

461459
full_task_set = TaskGraph(all_tasks, Graph(frozenset(all_tasks), frozenset()))
462460
yield self.verify("full_task_set", full_task_set, graph_config, parameters)

0 commit comments

Comments
 (0)