Skip to content

Commit bfc57d4

Browse files
authored
gh-117303: Don't detach in PyThreadState_DeleteCurrent() (#117304)
This fixes a crash in `test_threading.test_reinit_tls_after_fork()` when running with the GIL disabled. We already properly handle the case where the thread state is `_Py_THREAD_ATTACHED` in `tstate_delete_common()` -- we just need to remove an assertion. Keeping the thread attached means that a stop-the-world pause, such as for a `fork()`, won't commence until we remove our thread state from the interpreter's linked list. This prevents a crash when the child process tries to clean up the dead thread states.
1 parent 05e0b67 commit bfc57d4

File tree

1 file changed

+0
-2
lines changed

1 file changed

+0
-2
lines changed

Python/pystate.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,6 @@ static void
16601660
tstate_delete_common(PyThreadState *tstate)
16611661
{
16621662
assert(tstate->_status.cleared && !tstate->_status.finalized);
1663-
assert(tstate->state != _Py_THREAD_ATTACHED);
16641663
tstate_verify_not_active(tstate);
16651664
assert(!_PyThreadState_IsRunningMain(tstate));
16661665

@@ -1740,7 +1739,6 @@ _PyThreadState_DeleteCurrent(PyThreadState *tstate)
17401739
#ifdef Py_GIL_DISABLED
17411740
_Py_qsbr_detach(((_PyThreadStateImpl *)tstate)->qsbr);
17421741
#endif
1743-
tstate_set_detached(tstate, _Py_THREAD_DETACHED);
17441742
current_fast_clear(tstate->interp->runtime);
17451743
tstate_delete_common(tstate);
17461744
_PyEval_ReleaseLock(tstate->interp, NULL);

0 commit comments

Comments
 (0)