This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Steven Adams, amaury.forgeotdarc, belopolsky, meador.inge, serhiy.storchaka, vstinner, xiang.zhang
Date 2016-04-18.08:21:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1460967674.98.0.066369575698.issue26793@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-04-18 08:21:15vstinnersetrecipients: + vstinner, amaury.forgeotdarc, belopolsky, meador.inge, serhiy.storchaka, xiang.zhang, Steven Adams
2016-04-18 08:21:14vstinnersetmessageid: <1460967674.98.0.066369575698.issue26793@psf.upfronthosting.co.za>
2016-04-18 08:21:14vstinnerlinkissue26793 messages
2016-04-18 08:21:14vstinnercreate