Skip to content

Commit

Permalink
fix: handle correct mp pool
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoVoges committed Sep 1, 2023
1 parent a0bb378 commit 8e10be5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions kapitan/inventory/omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def inventory(self):
selected_targets = self.get_selected_targets()

# TODO: add flag for multiprocessing
use_mp = False
use_mp = True

if not use_mp:
nodes = {}
Expand All @@ -150,9 +150,17 @@ def inventory(self):

nodes = manager.dict()
mp.set_start_method("spawn", True) # platform independent
pool = cached.pool
r = pool.map_async(self.inventory_worker, [(self, target, nodes) for target in selected_targets])
r.wait()

if cached.pool:
r = cached.pool.map_async(self.inventory_worker, [(self, target, nodes) for target in selected_targets])
r.wait()
else:
with mp.Pool(len(selected_targets)) as pool:
r = pool.map_async(self.inventory_worker, [(self, target, nodes) for target in selected_targets])
r.wait()

# using nodes for reclass legacy code
nodes = dict(nodes)

# using nodes for reclass legacy code
return {"nodes": nodes}
Expand Down

0 comments on commit 8e10be5

Please sign in to comment.