bpo-40089: Fix threading._after_fork() (GH-19191)

If fork was not called by a thread spawned by threading.Thread,
threading._after_fork() now creates a _MainThread instance for
_main_thread, instead of a _DummyThread instance.
This commit is contained in:
Victor Stinner 2020-03-27 17:50:42 +01:00 committed by GitHub
parent 5a58c5280b
commit d8ff44ce4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -1423,7 +1423,15 @@ def _after_fork():
# fork() only copied the current thread; clear references to others.
new_active = {}
current = current_thread()
try:
current = _active[get_ident()]
except KeyError:
# fork() was called in a thread which was not spawned
# by threading.Thread. For example, a thread spawned
# by thread.start_new_thread().
current = _MainThread()
_main_thread = current
# reset _shutdown() locks: threads re-register their _tstate_lock below

View File

@ -0,0 +1,3 @@
Fix threading._after_fork(): if fork was not called by a thread spawned by
threading.Thread, threading._after_fork() now creates a _MainThread instance
for _main_thread, instead of a _DummyThread instance.