Gregory P. Smith added the comment:

You cannot safely use Python's os.fork() in a process that has threads.  
Because of POSIX.

The CPython interpreter is by definition not async signal safe so no Python 
code may safely be executed after the fork() system call if the process 
contained _any_ threads at fork() system call time.

The only reliable recommendation: *Never use os.fork()* (if your process _might 
ever_ contain any threads now or in the future started by your or any of your 
dependencies).

The closest thing to a fix to this is a bunch of band-aids to setup atfork 
functions to clear the state of known locks in the forked child. -- But even 
that can't guarantee things because that can't know about all locks.

The C standard library can contain locks.  malloc() for example.  Any C/C++ 
extension modules can contain locks of their own.  The problem isn't solvable 
within CPython.  Adding a clear of pystate.c's head_mutex after forking makes 
sense.  That may even get you further.  But you will encounter other problems 
of the same nature in the future.

related: https://bugs.python.org/issue6721 and 
https://bugs.python.org/issue16500

----------
nosy: +gregory.p.smith
resolution:  -> not a bug
stage:  -> needs patch
type:  -> enhancement
versions: +Python 3.7

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

Reply via email to