New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import error for multiprocessing in 2.7rc2 on Windows #53390
Comments
With a fresh install from python-2.7rc2.amd64.msi (rc1 is also affected) multiprocessing gives the following error: Python 2.7rc2 (r27rc2:82154, Jun 22 2010, 21:22:29) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import multiprocessing
>>> multiprocessing.Pool()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\multiprocessing\__init__.py", line 227, in Pool
return Pool(processes, initializer, initargs, maxtasksperchild)
File "C:\Python27\lib\multiprocessing\pool.py", line 89, in __init__
self._setup_queues()
File "C:\Python27\lib\multiprocessing\pool.py", line 181, in _setup_queues
from .queues import SimpleQueue
File "C:\Python27\lib\multiprocessing\queues.py", line 22, in <module>
from multiprocessing.synchronize import Lock, BoundedSemaphore, Semaphore, Condition
File "C:\Python27\lib\multiprocessing\synchronize.py", line 22, in <module>
from multiprocessing.forking import assert_spawning, Popen
File "C:\Python27\lib\multiprocessing\forking.py", line 158, in <module>
from ._multiprocessing import win32, Connection, PipeConnection
ImportError: No module named _multiprocessing I noticed that _multiprocessing.lib is not in Lib/multiprocessing/ but in libs/, so I don't know why there is a relative import here. |
Martin, any ideas? |
Here is the problem: there is no module multiprocessing._multiprocessing; _multiprocessing is a global module. However, multiprocessing/init.py imports _multiprocessing, providing multiprocessing._multiprocessing as a valid attribute. sys.modules['multiprocessing._multiprocessing'] is None. Now, on Windows, for some reason, from ._multiprocessing import win32 is used. In 2.6, this used to work. In 2.7, due to r81380, it stopped working (i.e. if I revert r81380, it works again). Adding Brett to the nosy list, as he made this change. |
Martin's analysis (and the description of the commit he refers to) indicates that the correct fix is Cuiseppe's suggestion to change the relative imports to absolute: from _multiprocessing import ... as the previous code was only working because, as a result of the bug fixed in r81380, from ._multiprocessing was falling back to this form anyway. |
Here's a patch implementing the suggested change. test_multiprocessing passes. I am just running the full test suite now. |
Full test suite also looks OK. |
the patch looks good to me - unless someone beats me to it, I'm going to commit it shortly to fix 2.7 |
Pushed it in r82489 - worked for me on Linux and OS/X. Please let me know if anything else comes up. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: