Skip to content
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