]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-137017: Ensure `Thread.is_alive()` only returns False after the underlying OS...
authorAbdul <abdulrasheedibrahim47@gmail.com>
Mon, 15 Sep 2025 11:13:37 +0000 (12:13 +0100)
committerGitHub <noreply@github.com>
Mon, 15 Sep 2025 11:13:37 +0000 (11:13 +0000)
Misc/NEWS.d/next/Library/2025-08-01-23-11-25.gh-issue-137017.0yGcNc.rst [new file with mode: 0644]
Modules/_threadmodule.c

diff --git a/Misc/NEWS.d/next/Library/2025-08-01-23-11-25.gh-issue-137017.0yGcNc.rst b/Misc/NEWS.d/next/Library/2025-08-01-23-11-25.gh-issue-137017.0yGcNc.rst
new file mode 100644 (file)
index 0000000..7c2c013
--- /dev/null
@@ -0,0 +1,3 @@
+Fix :obj:`threading.Thread.is_alive` to remain ``True`` until the underlying OS
+thread is fully cleaned up. This avoids false negatives in edge cases
+involving thread monitoring or premature :obj:`threading.Thread.is_alive` calls.
index a436a553db980246243a8e6d174e6b5a3392e4ad..c6d07b1360711cdcff6d11d700745b4910f72c8b 100644 (file)
@@ -711,6 +711,9 @@ PyThreadHandleObject_is_done(PyObject *op, PyObject *Py_UNUSED(dummy))
 {
     PyThreadHandleObject *self = PyThreadHandleObject_CAST(op);
     if (_PyEvent_IsSet(&self->handle->thread_is_exiting)) {
+        if (_PyOnceFlag_CallOnce(&self->handle->once, join_thread, self->handle) == -1) {
+            return NULL;
+        }
         Py_RETURN_TRUE;
     }
     else {