Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix parallel mode under Python-3.8 #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions fabric/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,31 +157,21 @@ def load_fabfile(path, importer=None):
# Get directory and fabfile name
directory, fabfile = os.path.split(path)
# If the directory isn't in the PYTHONPATH, add it so our import will work
added_to_path = False
index = None
if directory not in sys.path:
sys.path.insert(0, directory)
added_to_path = True
# If the directory IS in the PYTHONPATH, move it to the front temporarily,
# otherwise other fabfiles -- like Fabric's own -- may scoop the intended
# one.
else:
i = sys.path.index(directory)
if i != 0:
# Store index for later restoration
index = i
# Add to front, then remove from original position
sys.path.insert(0, directory)
del sys.path[i + 1]
# Perform the import (trimming off the .py)
imported = importer(os.path.splitext(fabfile)[0])
# Remove directory from path if we added it ourselves (just to be neat)
if added_to_path:
del sys.path[0]
# Put back in original index if we moved it
if index is not None:
sys.path.insert(index + 1, directory)
del sys.path[0]

# leave sys.path changed so that parallel mode can re-import tasks

# Actually load tasks
docstring, new_style, classic, default = load_tasks_from_module(imported)
Expand Down
8 changes: 6 additions & 2 deletions fabric/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import six
import sys
import textwrap
from importlib import import_module

from fabric import state
from fabric.utils import abort, warn, error
Expand Down Expand Up @@ -204,13 +205,15 @@ def _is_network_error_ignored():
return not state.env.use_exceptions_for['network'] and state.env.skip_bad_hosts


def _parallel_wrap(task, args, kwargs, queue, name, env):
def _parallel_wrap(task_module, task_name, args, kwargs, queue, name, env):
# Wrap in another callable that:
# * expands the env it's given to ensure parallel, linewise, etc are
# all set correctly and explicitly
# * nukes the connection cache to prevent shared-access problems
# * knows how to send the tasks' return value back over a Queue
# * captures exceptions raised by the task
module = import_module(task_module)
task = getattr(module, task_name)
state.env.update(env)
try:
state.connections.clear()
Expand Down Expand Up @@ -250,7 +253,8 @@ def _execute(task, host, my_env, args, kwargs, jobs, queue, multiprocessing):

# Stuff into Process wrapper
kwarg_dict = {
'task': task,
'task_module': task.__module__,
'task_name': task.__name__,
'args': args,
'kwargs': kwargs,
'queue': queue,
Expand Down