STINNER Victor <vstin...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue40089>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to