You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Multiprocessing spawn/forkserver fails to pass Queues #73151
Python fails to pass a Queue when calling Process with multiprocessing.set_start_method set to "spawn" or "forkserver".
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.5/multiprocessing/spawn.py", line 106, in spawn_main
exitcode = _main(fd)
File "/usr/lib/python3.5/multiprocessing/spawn.py", line 116, in _mainself= pickle.load(from_parent)
File "/usr/lib/python3.5/multiprocessing/synchronize.py", line 111, in __setstate__self._semlock = _multiprocessing.SemLock._rebuild(*state)
FileNotFoundError: [Errno 2] No such file or directory
the document(3x, 17.2.1.2) clearly mentions that 'spawn' doesnt inherit the file-handles (hence FileNotFoundError).
the document's examples has spawn() followed by join() where parent waits for the Child to finish and exits gracefully. The error "OSError: [Errno 9] Bad file descriptor" is seen for Child process.
Ok, this is really an error in your script. If you add p.join() to wait for the process to end, you'll see no error pops up. What really happens is that the parent process ends before the child is fully started, and the resource underlying the queue is cleaned up at this point.
So, while it might be possible to improve on this, it would risk fragilizing other use cases, and besides, this is not a problem that is likely to happen in real usage. Therefore, I'd rather close this issue.
On MacOS Catalina 10.15.4, I still see this problem occasionally even with p.join() added. See https://bugs.python.org/msg365251 and subsequent messages.
Ok, this is really an error in your script. If you add p.join() to wait for the process to end, you'll see no error pops up. What really happens is that the parent process ends before the child is fully started, and the resource underlying the queue is cleaned up at this point.
Activity
duckythescientist commentedon Dec 14, 2016
Python fails to pass a Queue when calling Process with multiprocessing.set_start_method set to "spawn" or "forkserver".
Here is a minimized example:
Also, this fails when the Queue is implicitly passed to the child.
Windows (which defaults to "spawn" style multiprocessing) does not seem to have this issue (at least in 2.7.12).
piython commentedon Dec 15, 2016
hi,
few comments on this: [when tested with 'spawn']
am not a core developer yet and still trying to learn and contribute.
Thanks
pitrou commentedon Jul 22, 2017
Ok, this is really an error in your script. If you add
p.join()to wait for the process to end, you'll see no error pops up. What really happens is that the parent process ends before the child is fully started, and the resource underlying the queue is cleaned up at this point.pitrou commentedon Jul 22, 2017
More exactly, since the child process is not "daemonic", the parent process waits for it to end, but after collecting the queue's resources.
pitrou commentedon Jul 22, 2017
So, while it might be possible to improve on this, it would risk fragilizing other use cases, and besides, this is not a problem that is likely to happen in real usage. Therefore, I'd rather close this issue.
mouse07410 commentedon Mar 29, 2020
On MacOS Catalina 10.15.4, I still see this problem occasionally even with p.join() added. See https://bugs.python.org/msg365251 and subsequent messages.
Also, see https://bugs.python.org/issue40106.
geryogam commentedon May 8, 2022
And if you don’t want to
jointhe process explicitly like @pitrou suggested, here is an alternative: https://stackoverflow.com/a/72164506/2326961