https://github.com/python/cpython/commit/88d137a891a82e04437973cdda7ef6a96a1a2b01
commit: 88d137a891a82e04437973cdda7ef6a96a1a2b01
branch: 3.15
author: Ahmed Semih Ă–zmekik <[email protected]>
committer: ZeroIntensity <[email protected]>
date: 2026-11-12T00:45:42Z
summary:
[3.15] gh-161712: Read the clock once in `ThreadHandle_join()` (GH-161771)
Py_MAX() evaluated _PyDeadline_Get() twice. If the deadline passed
between the two calls, the negative second value was used as the
timeout, which means no timeout, and Thread.join(timeout) could block
forever. main already reads it once since gh-157495.
files:
A Misc/NEWS.d/next/Library/2026-11-10-19-00-00.gh-issue-161712.HyM9PA.rst
M Modules/_threadmodule.c
diff --git
a/Misc/NEWS.d/next/Library/2026-11-10-19-00-00.gh-issue-161712.HyM9PA.rst
b/Misc/NEWS.d/next/Library/2026-11-10-19-00-00.gh-issue-161712.HyM9PA.rst
new file mode 100644
index 00000000000000..c7f9264951d88c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-11-10-19-00-00.gh-issue-161712.HyM9PA.rst
@@ -0,0 +1,3 @@
+Fix :meth:`threading.Thread.join` with a timeout blocking forever when the
+deadline passed between the two reads of the clock used to compute the time
+left.
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 81ff9af1bd97c6..d5203247272ac2 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -571,7 +571,8 @@ ThreadHandle_join(ThreadHandle *self, PyTime_t timeout_ns)
if (deadline) {
// _PyDeadline_Get will return a negative value if the deadline has
// been exceeded.
- timeout_ns = Py_MAX(_PyDeadline_Get(deadline), 0);
+ timeout_ns = _PyDeadline_Get(deadline);
+ timeout_ns = Py_MAX(timeout_ns, 0);
}
if (timeout_ns) {
_______________________________________________
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]