-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
multiprocessing.Pool cannot import from main #118
Comments
Further testing reveals the issue is with dill
Returns the same error:
Error does not occur when pickle is used in place of dill (even if dill is imported). |
This is not only the case for defined |
@justinlovinger @DavidLP: I'm not seeing this error on MacOS. However, do I see that at least @justinlovinger is using Windows. On Windows, you are missing Try:
Let me know if this fixes your code, (and close the ticket)... or if it doesn't please let me know what you are seeing that's different. |
Using I use Windows by the way. |
@DavidLP: I've tried it on windows and I am not seeing any problems. So, let's figure out what in your environment is triggering this. Can you provide me your code and traceback, as well as python and system information? |
|
I have the same issue on Windows 10 using the same code as OP. Any suggestions on how to fix it?
Running the above code gives me the same error
|
@SjurdurS: It's a common error on windows, and it overwhelmingly comes from one of two things:
Sorry this issue seems to be stale for everyone... I'm at an impasse as I can produce the error by doing either of the two things enumerated above, but can't reproduce the error if both of the above are resolved. Not sure what to do here. If there's no other comments that can elucidate what is different about your environment, and why you are all seeing errors when using |
It works if you put the functions as methods:
However, if you try to import a package which you want to use within one of the methods for instances:
I receive:
The solution I found is to put import math and declare it as a class variable. But I would be happy if someone found a better way.
|
I can reproduce this problem when I install only My configuration is:
Test example: # test_example_multiprocess.py
def func1():
print("Hello world!")
def func2():
func1()
if __name__ == "__main__":
from multiprocess import Process
proc = Process(target=func2)
proc.start()
proc.join() and this is the traceback: (py37) D:\vic\Desktop>python test_example_multiprocess.py
Process Process-1:
Traceback (most recent call last):
File "C:\GNU\Anaconda3\envs\py37\lib\site-packages\multiprocess\process.py",
line 297, in _bootstrap
self.run()
File "C:\GNU\Anaconda3\envs\py37\lib\site-packages\multiprocess\process.py",
line 99, in run
self._target(*self._args, **self._kwargs)
File "test_example_multiprocess.py", line 9, in func2
func1()
NameError: name 'func1' is not defined
(py37) D:\vic\Desktop> The same snippet works when I use the standard # test_example_multiprocessing.py
def func1():
print("Hello world!")
def func2():
func1()
if __name__ == "__main__":
from multiprocessing import Process
proc = Process(target=func2)
proc.start()
proc.join() (py37) D:\vic\Desktop>python test_example_multiprocessing.py
Hello world! The same problem occurs with another environment using Python 3.6.10 and multiprocess 0.70.9, and it does not occur with Python 3.5.6 and multiprocess 0.70.5. So it seems something occurred between these two versions that introduced this issue. Edit: I was diving a bit more and in fact the multiprocess version is not the problem, it comes from dill. For Python 3.6.10 and Python 3.7.6, multiprocess 0.70.9 works with dill 0.2.8.2 and has the bug with dill 0.2.9 or newer. I have the feeling this is dill issue #323. |
I'm going to label this a bug, even though it was a |
@mmckerns Dear mmckerns, I don't understand why this post is closed. Because the issue is not solved! I installed the latest pathos on windows 10. If you run JustinLovinger's code in interactive jupyterlab mode, you still got "NameError: name 'foo' is not defined". But it is indeed working in scripting mode. I suggest reopen this post and solve this annoying bug completely. Thank you very much. |
@simonnier: Did you run the code in Jupyter in a single cell or in multiple cells? Jupyter messes with the structure of the global namespace (each cell is in its own local namespace), and also messes with parallelism. This issue is closed because it was for the behavior in python in general. Working across multiple cells in Jupyter, for example, should only work under certain circumstances, but isn't guaranteed for this or several other features of |
Running this script on Windows 10 results in:
The same occurs with pathos.multiprocessing.ProcessPool.
pathos.parallel.ParallelPool does not have this issue.
The text was updated successfully, but these errors were encountered: