Skip to content

Commit aae4ad7

Browse files
abdoulrasheedmiss-islington
authored andcommitted
pythongh-137017: Ensure Thread.is_alive() only returns False after the underlying OS thread exits (pythongh-137315)
(cherry picked from commit aa9ceb1) Co-authored-by: Abdul <abdulrasheedibrahim47@gmail.com>
1 parent 2fd8f03 commit aae4ad7

2 files changed

Lines changed: 6 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 :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
@@ -657,6 +657,9 @@ PyThreadHandleObject_is_done(PyThreadHandleObject *self,
657657
PyObject *Py_UNUSED(ignored))
658658
{
659659
if (_PyEvent_IsSet(&self->handle->thread_is_exiting)) {
660+
if (_PyOnceFlag_CallOnce(&self->handle->once, join_thread, self->handle) == -1) {
661+
return NULL;
662+
}
660663
Py_RETURN_TRUE;
661664
}
662665
else {

0 commit comments

Comments
 (0)