Message127414
Actually, forget that (!). The following patch seems to work:
Index: Lib/multiprocessing/forking.py
===================================================================
--- Lib/multiprocessing/forking.py (révision 88224)
+++ Lib/multiprocessing/forking.py (copie de travail)
@@ -474,7 +474,8 @@
else:
dirs = [os.path.dirname(main_path)]
- assert main_name not in sys.modules, main_name
+ if main_name != '__main__':
+ assert main_name not in sys.modules, main_name
file, path_name, etc = imp.find_module(main_name, dirs)
try:
# We would like to do "imp.load_module('__main__', ...)"
Index: Lib/test/__main__.py
===================================================================
--- Lib/test/__main__.py (révision 88224)
+++ Lib/test/__main__.py (copie de travail)
@@ -1,13 +1,16 @@
from test import regrtest, support
+# Issue #10845: avoid executing toplevel code if imported by multiprocessing
+# (which is smart enough to import the module under another name).
+if __name__ == "__main__":
-TEMPDIR, TESTCWD = regrtest._make_temp_dir_for_build(regrtest.TEMPDIR)
-regrtest.TEMPDIR = TEMPDIR
-regrtest.TESTCWD = TESTCWD
+ TEMPDIR, TESTCWD = regrtest._make_temp_dir_for_build(regrtest.TEMPDIR)
+ regrtest.TEMPDIR = TEMPDIR
+ regrtest.TESTCWD = TESTCWD
-# Run the tests in a context manager that temporary changes the CWD to a
-# temporary and writable directory. If it's not possible to create or
-# change the CWD, the original CWD will be used. The original CWD is
-# available from support.SAVEDCWD.
-with support.temp_cwd(TESTCWD, quiet=True):
- regrtest.main()
+ # Run the tests in a context manager that temporary changes the CWD to a
+ # temporary and writable directory. If it's not possible to create or
+ # change the CWD, the original CWD will be used. The original CWD is
+ # available from support.SAVEDCWD.
+ with support.temp_cwd(TESTCWD, quiet=True):
+ regrtest.main() |
|
Date |
User |
Action |
Args |
2011-01-29 13:29:32 | pitrou | set | recipients:
+ pitrou, brett.cannon, georg.brandl, terry.reedy, ncoghlan, vstinner, jnoller, michael.foord, brian.curtin, asksol |
2011-01-29 13:29:32 | pitrou | set | messageid: <1296307772.82.0.451932606692.issue10845@psf.upfronthosting.co.za> |
2011-01-29 13:29:32 | pitrou | link | issue10845 messages |
2011-01-29 13:29:32 | pitrou | create | |
|