Skip to content

Commit

Permalink
fix: parallel execution
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-kondakov committed Jun 10, 2024
1 parent 3019a1a commit fcf4c1c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions fabric/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ def execute(task, *args, **kwargs):
# if it can't.
try:
import multiprocessing
ctx = multiprocessing.get_context('fork')
queue = ctx.Queue()
except ImportError:
import traceback
tb = traceback.format_exc()
Expand All @@ -338,12 +340,11 @@ def execute(task, *args, **kwargs):
traceback.) Please make sure the module is installed
or that the above ImportError is fixed.""")
else:
multiprocessing = None
ctx = None
queue = None

# Get pool size for this task
pool_size = task.get_pool_size(my_env['all_hosts'], state.env.pool_size)
# Set up job queue in case parallel is needed
queue = multiprocessing.Queue() if parallel else None
jobs = JobQueue(pool_size, queue)
if state.output.debug:
jobs._debug = True
Expand All @@ -355,7 +356,7 @@ def execute(task, *args, **kwargs):
try:
results[host] = _execute(
task, host, my_env, args, new_kwargs, jobs, queue,
multiprocessing
ctx
)
except NetworkError as e:
results[host] = e
Expand Down

0 comments on commit fcf4c1c

Please sign in to comment.