mirror of
https://github.com/python/cpython.git
synced 2025-08-06 01:49:02 +00:00
[3.12] gh-102512: Turn _DummyThread into _MainThread after os.fork() called from a foreign thread (GH-113261) (GH-114430)
Always set a _MainThread as a main thread after os.fork() is called from
a thread started not by the threading module.
A new _MainThread was already set as a new main thread after fork if
threading.current_thread() was not called for a foreign thread before fork.
Now, if it was called before fork, the implicitly created _DummyThread will
be turned into _MainThread after fork.
It fixes, in particularly, an incompatibility of _DummyThread with
the threading shutdown logic which relies on the main thread
having tstate_lock.
(cherry picked from commit 49785b06de
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
This commit is contained in:
parent
d1f731ff08
commit
1bd2c93474
3 changed files with 98 additions and 9 deletions
|
@ -1460,7 +1460,6 @@ class _DummyThread(Thread):
|
|||
def __init__(self):
|
||||
Thread.__init__(self, name=_newname("Dummy-%d"),
|
||||
daemon=_daemon_threads_allowed())
|
||||
|
||||
self._started.set()
|
||||
self._set_ident()
|
||||
if _HAVE_THREAD_NATIVE_ID:
|
||||
|
@ -1685,6 +1684,11 @@ def _after_fork():
|
|||
# its new value since it can have changed.
|
||||
thread._reset_internal_locks(True)
|
||||
ident = get_ident()
|
||||
if isinstance(thread, _DummyThread):
|
||||
thread.__class__ = _MainThread
|
||||
thread._name = 'MainThread'
|
||||
thread._daemonic = False
|
||||
thread._set_tstate_lock()
|
||||
thread._ident = ident
|
||||
new_active[ident] = thread
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue