gh-153005: Use a monotonic clock for concurrent.interpreters Queue timeouts#154156
Open
fedonman wants to merge 1 commit into
Open
gh-153005: Use a monotonic clock for concurrent.interpreters Queue timeouts#154156fedonman wants to merge 1 commit into
fedonman wants to merge 1 commit into
Conversation
…eue timeouts Queue.get() and Queue.put() computed their timeout deadline from time.time(), the wall clock. If the system clock was stepped (NTP, a manual change) while a call was blocked, the timeout could over- or under-wait. queue.Queue uses time.monotonic() for the same reason. Compute the deadline and check it against time.monotonic() instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
concurrent.interpreters.Queue.get()andQueue.put()computed their timeout deadline fromtime.time(), the wall clock:If the system clock is stepped (an NTP correction, a manual change) while a call is blocked, the deadline is off by the size of the adjustment, so the call can over- or under-wait.
queue.Queue, which this queue is meant to be compatible with, usestime.monotonic()precisely to avoid that.This computes the deadline and checks it against
time.monotonic()instead, in bothget()andput().The issue also mentions that
int(timeout)truncates a float timeout. That part was left out here on purpose: in the earlier PR #153006 a core reviewer asked to keep the clock change separate and to discuss theint()conversion (and the matching docs and other stdlib queues) first. This PR is only the monotonic-clock fix.