[issue40089] Add _at_fork_reinit() method to locks
STINNER Victor
report at bugs.python.org
Fri Mar 27 12:29:48 EDT 2020
STINNER Victor <vstinner at python.org> added the comment:
_at_fork() has a bug: it creates a _DummyThread instead of a _MainThread. Example:
---
import os, _thread, threading, time
def fork_in_thread():
pid = os.fork()
if pid:
# parent
os._exit(0)
# child process
print(f"child process: {threading.current_thread()=}")
print(f"child process: {threading._main_thread=}")
print(f"parent process: {threading.current_thread()=}")
print(f"parent process: {threading._main_thread=}")
_thread.start_new_thread(fork_in_thread, ())
# block the main thread: fork_in_thread() exit the process
time.sleep(60)
---
Output:
---
parent process: threading.current_thread()=<_MainThread(MainThread, started 139879200077632)>
parent process: threading._main_thread=<_MainThread(MainThread, started 139879200077632)>
child process: threading.current_thread()=<_DummyThread(Dummy-1, started daemon 139878980245248)>
child process: threading._main_thread=<_DummyThread(Dummy-1, started daemon 139878980245248)>
---
My PR 19191 fix the issue:
---
parent process: threading.current_thread()=<_MainThread(MainThread, started 140583665170240)>
parent process: threading._main_thread=<_MainThread(MainThread, started 140583665170240)>
child process: threading.current_thread()=<_MainThread(MainThread, started 140583445075712)>
child process: threading._main_thread=<_MainThread(MainThread, started 140583445075712)>
---
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40089>
_______________________________________
More information about the Python-bugs-list
mailing list