Skip to content

Commit 9e13cc2

Browse files
miss-islingtonAbdoulrasheedcolesbury
authored
[3.14] gh-137017: Ensure Thread.is_alive() only returns False after the underlying OS thread exits (gh-137315) (gh-138916)
(cherry picked from commit aa9ceb1) Co-authored-by: Abdul <abdulrasheedibrahim47@gmail.com> Co-authored-by: Sam Gross <colesbury@gmail.com>
1 parent 85dabb9 commit 9e13cc2

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
@@ -690,6 +690,9 @@ PyThreadHandleObject_is_done(PyObject *op, PyObject *Py_UNUSED(dummy))
690690
{
691691
PyThreadHandleObject *self = PyThreadHandleObject_CAST(op);
692692
if (_PyEvent_IsSet(&self->handle->thread_is_exiting)) {
693+
if (_PyOnceFlag_CallOnce(&self->handle->once, join_thread, self->handle) == -1) {
694+
return NULL;
695+
}
693696
Py_RETURN_TRUE;
694697
}
695698
else {

0 commit comments

Comments
 (0)