Skip to content

Commit

Permalink
bpo-40089: Fix threading._after_fork() (GH-19191) (GH-19194)
Browse files Browse the repository at this point in the history
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.
(cherry picked from commit d8ff44c)

Co-authored-by: Victor Stinner <vstinner@python.org>
  • Loading branch information
miss-islington and vstinner committed Apr 7, 2020
1 parent 8bd84e7 commit 6318e45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 6318e45

Please sign in to comment.