STINNER Victor added the comment: Hum, I should elaborate my explanation :-) os.fork() removes all threads except of the current thread. It's clearly stated in the fork manual page, but the Python os.fork() doesn't say anything about threads. https://docs.python.org/dev/library/os.html#os.fork
Short example: --- import os, threading, time t = threading.Thread(target=time.sleep, args=(3.0,)) t.start() print("First process", threading.enumerate()) pid = os.fork() if pid != 0: os.waitpid(pid, 0) else: print("Child process", threading.enumerate()) --- Output: --- First process [<_MainThread(MainThread, started 140737353955072)>, <Thread(Thread-1, started 140737216849664)>] Child process [<_MainThread(MainThread, started 140737353955072)>] --- The thread is removed in the child process. Again, *don't create threads before fork*. More generally, don't create any resource before fork: don't open files, don't create locks, don't open a connection to a database, don't start an event loop, etc. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26793> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com