Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.