Issue #10845: Improve compatibility between multiprocessing on Windows and package...
authorNick Coghlan <ncoghlan@gmail.com>
Sun, 30 Jan 2011 01:24:08 +0000 (01:24 +0000)
committerNick Coghlan <ncoghlan@gmail.com>
Sun, 30 Jan 2011 01:24:08 +0000 (01:24 +0000)
Lib/multiprocessing/forking.py
Misc/NEWS

index d2a320845365707011bb221abc48aa308a6f3844..8ddddb60b5ec15c6059b4c84b869f31f0cb0a5f9 100644 (file)
@@ -459,12 +459,20 @@ def prepare(data):
         process.ORIGINAL_DIR = data['orig_dir']
 
     if 'main_path' in data:
+        # XXX (ncoghlan): The following code makes several bogus
+        # assumptions regarding the relationship between __file__
+        # and a module's real name. See PEP 302 and issue #10845
         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':
+        if main_name == '__main__':
+            main_module = sys.modules['__main__']
+            main_module.__file__ = main_path
+        elif main_name != 'ipython':
+            # Main modules not actually called __main__.py may
+            # contain additional code that should still be executed
             import imp
 
             if main_path is None:
index ed7e5de35fea9f275accd0f6488159da9873dc4e..57b2440eda52024a70ecd25e1c6e524cbe1e40ef 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #10845: Mitigate the incompatibility between the multiprocessing
+  module on Windows and the use of package, zipfile or directory execution
+  by special casing main modules that actually *are* called __main__.py.
+
 - Issue #11045: Protect logging call against None argument.
 
 - Issue #11052: Correct IDLE menu accelerators on Mac OS X for Save