gh-153005: Fix timeout handling in concurrent.interpreters.Queue - #153006
gh-153005: Fix timeout handling in concurrent.interpreters.Queue#153006tonghuaroot wants to merge 1 commit into
Conversation
Queue.get() and Queue.put() converted the timeout argument with int(), truncating a floating-point timeout to whole seconds, so a timeout below one second became non-blocking. Use the value as given, reject a negative or NaN timeout with ValueError, and base the deadline on time.monotonic(), matching queue.Queue.
picnixz
left a comment
There was a problem hiding this comment.
This PR does two things:
- it moved to a monotonic counter
- it supports floating-point timeouts
Please open 2 separate PRs and update documentation accordingly. The first can be considered a bug fix, the second is a feature IMO.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
I'm closing it in advance but each PR should focus on its own purpose. |
|
As for the truncation to int, I would actually leave it as is for now. We need to discuss why it was like this first. And possibly change the docs as well. What about other queues implementations in the stdlib? |
Fixes #153005.
Queue.get()andQueue.put()converted thetimeoutargument withint().This changes the timeout handling to match
queue.Queue:whole seconds, so a sub-second timeout actually blocks.
ValueError. Previously a smallnegative float was truncated to
0and silently ignored, and a NaN wouldhave made the wait loop run forever.
time.monotonic()instead oftime.time(),so it is unaffected by system clock adjustments.
The wait is still a poll loop with a 10 ms delay, so the timeout resolution is
bounded by that interval; this PR does not change the polling design.