Skip to content

Commit dc933c0

Browse files
committed
gh-137017: Ensure is_alive() remains True until the underlying OS thread is fully cleaned up
1 parent d658b90 commit dc933c0

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix `threading.Thread.is_alive()` to remain `True` until the underlying OS
2+
thread is fully cleaned up. This avoids false negatives in edge cases
3+
involving thread monitoring or premature `is_alive()` calls.

Modules/_threadmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,10 @@ PyThreadHandleObject_is_done(PyObject *op, PyObject *Py_UNUSED(dummy))
704704
{
705705
PyThreadHandleObject *self = PyThreadHandleObject_CAST(op);
706706
if (_PyEvent_IsSet(&self->handle->thread_is_exiting)) {
707+
if (_PyOnceFlag_CallOnce(&self->handle->once, join_thread, self->handle) == -1) {
708+
PyErr_SetString(PyExc_RuntimeError, "failed to join thread");
709+
return NULL;
710+
}
707711
Py_RETURN_TRUE;
708712
}
709713
else {

0 commit comments

Comments
 (0)