Skip to content

Commit 9503cd5

Browse files
committed
gh-117303: Don't detach in PyThreadState_DeleteCurrent()
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 669ef49 commit 9503cd5

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
@@ -1658,7 +1658,6 @@ static void
16581658
tstate_delete_common(PyThreadState *tstate)
16591659
{
16601660
assert(tstate->_status.cleared && !tstate->_status.finalized);
1661-
assert(tstate->state != _Py_THREAD_ATTACHED);
16621661
tstate_verify_not_active(tstate);
16631662
assert(!_PyThreadState_IsRunningMain(tstate));
16641663

@@ -1738,7 +1737,6 @@ _PyThreadState_DeleteCurrent(PyThreadState *tstate)
17381737
#ifdef Py_GIL_DISABLED
17391738
_Py_qsbr_detach(((_PyThreadStateImpl *)tstate)->qsbr);
17401739
#endif
1741-
tstate_set_detached(tstate, _Py_THREAD_DETACHED);
17421740
current_fast_clear(tstate->interp->runtime);
17431741
tstate_delete_common(tstate);
17441742
_PyEval_ReleaseLock(tstate->interp, NULL);

0 commit comments

Comments
 (0)