◐ Shell
clean mode source ↗

Message 367516 - Python tracker

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.