Message263655
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. |
|
Date |
User |
Action |
Args |
2016-04-18 08:21:15 | vstinner | set | recipients:
+ vstinner, amaury.forgeotdarc, belopolsky, meador.inge, serhiy.storchaka, xiang.zhang, Steven Adams |
2016-04-18 08:21:14 | vstinner | set | messageid: <1460967674.98.0.066369575698.issue26793@psf.upfronthosting.co.za> |
2016-04-18 08:21:14 | vstinner | link | issue26793 messages |
2016-04-18 08:21:14 | vstinner | create | |
|