Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 6 additions & 3 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,13 @@ ThreadHandle_join(ThreadHandle *self, PyTime_t timeout_ns)
int detach = 1;
while (!PyEvent_WaitTimed(&self->thread_is_exiting, timeout_ns, detach)) {
if (deadline) {
// _PyDeadline_Get will return a negative value if the deadline has
// been exceeded.
// Read the clock once. _PyDeadline_Get() returns a negative value
// once the deadline has passed, and a negative timeout would mean
// no timeout at all (gh-161712).
timeout_ns = _PyDeadline_Get(deadline);
timeout_ns = Py_MAX(timeout_ns, 0);
if (timeout_ns < 0) {
timeout_ns = 0;
}
}

if (timeout_ns) {
Expand Down
Loading