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) {