Skip to content

Commit aa9ceb1

Browse files
gh-137017: Ensure Thread.is_alive() only returns False after the underlying OS thread exits (gh-137315)
1 parent cb07bd2 commit aa9ceb1

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix :obj:`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 :obj:`threading.Thread.is_alive` calls.

Modules/_threadmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,9 @@ PyThreadHandleObject_is_done(PyObject *op, PyObject *Py_UNUSED(dummy))
711711
{
712712
PyThreadHandleObject *self = PyThreadHandleObject_CAST(op);
713713
if (_PyEvent_IsSet(&self->handle->thread_is_exiting)) {
714+
if (_PyOnceFlag_CallOnce(&self->handle->once, join_thread, self->handle) == -1) {
715+
return NULL;
716+
}
714717
Py_RETURN_TRUE;
715718
}
716719
else {

0 commit comments

Comments
 (0)