Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 793ee1f

Browse files
committed
Issue #10845: Improve compatibility between multiprocessing on Windows and package, zipfile and directory execution (Reviewed by Antoine Pitrou and approved by Georg Brandl)
1 parent c7bb159 commit 793ee1f

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lib/multiprocessing/forking.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,20 @@ def prepare(data):
459459
process.ORIGINAL_DIR = data['orig_dir']
460460

461461
if 'main_path' in data:
462+
# XXX (ncoghlan): The following code makes several bogus
463+
# assumptions regarding the relationship between __file__
464+
# and a module's real name. See PEP 302 and issue #10845
462465
main_path = data['main_path']
463466
main_name = os.path.splitext(os.path.basename(main_path))[0]
464467
if main_name == '__init__':
465468
main_name = os.path.basename(os.path.dirname(main_path))
466469

467-
if main_name != 'ipython':
470+
if main_name == '__main__':
471+
main_module = sys.modules['__main__']
472+
main_module.__file__ = main_path
473+
elif main_name != 'ipython':
474+
# Main modules not actually called __main__.py may
475+
# contain additional code that should still be executed
468476
import imp
469477

470478
if main_path is None:

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Core and Builtins
1616
Library
1717
-------
1818

19+
- Issue #10845: Mitigate the incompatibility between the multiprocessing
20+
module on Windows and the use of package, zipfile or directory execution
21+
by special casing main modules that actually *are* called __main__.py.
22+
1923
- Issue #11045: Protect logging call against None argument.
2024

2125
- Issue #11052: Correct IDLE menu accelerators on Mac OS X for Save

0 commit comments

Comments
 (0)