https://github.com/python/cpython/commit/c26254066c7941209782b8c59e6efc3818d237e6 commit: c26254066c7941209782b8c59e6efc3818d237e6 branch: 3.14 author: Miss Islington (bot) <[email protected]> committer: vstinner <[email protected]> date: 2026-11-13T02:26:53+01:00 summary:
[3.14] gh-161712: Read the clock once in `ThreadHandle_join()` (GH-161771) (#161843) [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. (cherry picked from commit 88d137a891a82e04437973cdda7ef6a96a1a2b01) Co-authored-by: Ahmed Semih Ă–zmekik <[email protected]> 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 d0847af17cc625..9a1a45e399e629 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -541,7 +541,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]
