https://github.com/python/cpython/commit/9e13cc28962ce92ea080cb7988d95fff70955d96
commit: 9e13cc28962ce92ea080cb7988d95fff70955d96
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: colesbury <[email protected]>
date: 2025-10-07T17:37:31Z
summary:

[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 aa9ceb17215af21ed6618d6f7ccb5bf57ca57101)

Co-authored-by: Abdul <[email protected]>
Co-authored-by: Sam Gross <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-08-01-23-11-25.gh-issue-137017.0yGcNc.rst
M 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
index 00000000000000..7c2c013016d72e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-08-01-23-11-25.gh-issue-137017.0yGcNc.rst
@@ -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.
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 775cd704cda4ed..26d3c0a2266b71 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -690,6 +690,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 {

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to