cpython: 5d88c1d413b9 (original) (raw)
Mercurial > cpython
changeset 99207:5d88c1d413b9 2.7
Close #10128: don't rerun __main__.py in multiprocessing - backports issue #10845's mitigation of incompatibilities between the multiprocessing module and directory and zipfile execution - Multiprocessing on Windows will now automatically skip rerunning top level __main__.py modules in spawned processes, rather than failing with AssertionError [#10128]
Nick Coghlan ncoghlan@gmail.com | |
---|---|
date | Thu, 19 Nov 2015 12:59:39 +1000 |
parents | 106c49edbb12 |
children | 5588ec7f208e |
files | Lib/multiprocessing/forking.py Misc/NEWS |
diffstat | 2 files changed, 20 insertions(+), 1 deletions(-)[+] [-] Lib/multiprocessing/forking.py 16 Misc/NEWS 5 |
line wrap: on
line diff
--- a/Lib/multiprocessing/forking.py +++ b/Lib/multiprocessing/forking.py @@ -470,12 +470,26 @@ def prepare(data): process.ORIGINAL_DIR = data['orig_dir'] if 'main_path' in data:
# XXX (ncoghlan): The following code makes several bogus[](#l1.7)
# assumptions regarding the relationship between __file__[](#l1.8)
# and a module's real name. See PEP 302 and issue #10845[](#l1.9)
# The problem is resolved properly in Python 3.4+, as[](#l1.10)
# described in issue #19946[](#l1.11)
+ main_path = data['main_path'] main_name = os.path.splitext(os.path.basename(main_path))[0] if main_name == 'init': main_name = os.path.basename(os.path.dirname(main_path))
if main_name != 'ipython':[](#l1.18)
if main_name == '__main__':[](#l1.19)
# For directory and zipfile execution, we assume an implicit[](#l1.20)
# "if __name__ == '__main__':" around the module, and don't[](#l1.21)
# rerun the main module code in spawned processes[](#l1.22)
main_module = sys.modules['__main__'][](#l1.23)
main_module.__file__ = main_path[](#l1.24)
elif main_name != 'ipython':[](#l1.25)
# Main modules not actually called __main__.py may[](#l1.26)
# contain additional code that should still be executed[](#l1.27) import imp[](#l1.28)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -55,6 +55,11 @@ Core and Builtins Library ------- +- Issue #10128: backport issue #10845's mitigation of incompatibilities between