Skip to content

gh-134381: Improve thread safety in _PyThread_AfterFork by preserving not-started handles #134514

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 8 commits into from
May 23, 2025
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve thread safety in :class:`_PyThread_AfterFork` by preserving not-started handles
5 changes: 5 additions & 0 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ _PyThread_AfterFork(struct _pythread_runtime_state *state)
continue;
}

// keep not_start handles – they are safe to start in the child
if (handle->state == THREAD_HANDLE_NOT_STARTED){
continue;
}

// Mark all threads as done. Any attempts to join or detach the
// underlying OS thread (if any) could crash. We are the only thread;
// it's safe to set this non-atomically.
Expand Down
Loading