Skip to content

Commit

Permalink
Customize: Patch multiprocessing to make it work when all variables a…
Browse files Browse the repository at this point in the history
…re removed
  • Loading branch information
ccordoba12 committed Oct 29, 2018
1 parent 4263a3c commit 3a7dcb4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions spyder_kernels/customize/spydercustomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,35 @@ def __init__(self, *args, **kwargs):
pass


# =============================================================================
# Multiprocessing adjustments
# =============================================================================
# This patch is only needed on Windows and Python 3
if os.name == 'nt' and not PY2:
# This could fail with changes in Python itself, so we protect it
# with a try/except
try:
import multiprocessing.spawn
_old_preparation_data = multiprocessing.spawn.get_preparation_data

def _patched_preparation_data(name):
"""
Patched get_preparation_data to work when all variables are
removed before execution.
"""
try:
return _old_preparation_data(name)
except AttributeError:
main_module = sys.modules['__main__']
# Any string for __spec__ does the job
main_module.__spec__ = ''
return _old_preparation_data(name)

multiprocessing.spawn.get_preparation_data = _patched_preparation_data
except Exception:
pass


#==============================================================================
# Pdb adjustments
#==============================================================================
Expand Down

0 comments on commit 3a7dcb4

Please sign in to comment.