Antoine Pitrou <solip...@pitrou.net> added the comment:

I can reproduce on Ubuntu 18.04 with git master.

Here is a better example which clearly shows the issue:
https://gist.github.com/pitrou/d9784d5ec679059cd02fce4b38ea2fa6

After a few runs, you'll see that the child Process hangs when trying to flush 
the standard streams:
Timeout (0:00:01)!
Thread 0x00007efbff6c0080 (most recent call first):
  File "/home/antoine/cpython/default/Lib/multiprocessing/util.py", line 435 in 
_flush_std_streams
  File "/home/antoine/cpython/default/Lib/multiprocessing/process.py", line 335 
in _bootstrap
  File "/home/antoine/cpython/default/Lib/multiprocessing/popen_fork.py", line 
71 in _launch
  File "/home/antoine/cpython/default/Lib/multiprocessing/popen_fork.py", line 
19 in __init__
  File "/home/antoine/cpython/default/Lib/multiprocessing/context.py", line 276 
in _Popen
  File "/home/antoine/cpython/default/Lib/multiprocessing/context.py", line 224 
in _Popen
  File "/home/antoine/cpython/default/Lib/multiprocessing/process.py", line 121 
in start
  File "/home/antoine/cpython/default/bpo40399.py", line 25 in <module>
Child process failed!


@Delgan, mixing processes and threads is problematic with the default settings. 
 See here:
https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods

"""Note that safely forking a multithreaded process is problematic."""

If you call `multiprocessing.set_start_method("forkserver")` at the start of 
your program, the problem will disappear.

----------
nosy: +pitrou, vstinner
title: Program hangs if process created right after adding object to a Queue -> 
IO streams locking can be broken after fork() with threads
versions: +Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40399>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to