Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-153005: Fix timeout handling in concurrent.interpreters.Queue - #153006

Closed
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:fix-interpreters-queue-timeout
Closed

gh-153005: Fix timeout handling in concurrent.interpreters.Queue#153006
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:fix-interpreters-queue-timeout

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #153005.

Queue.get() and Queue.put() converted the timeout argument with int().
This changes the timeout handling to match queue.Queue:

  • A floating-point timeout is used as given instead of being truncated to
    whole seconds, so a sub-second timeout actually blocks.
  • A negative or NaN timeout now raises ValueError. Previously a small
    negative float was truncated to 0 and silently ignored, and a NaN would
    have made the wait loop run forever.
  • The deadline is computed with time.monotonic() instead of time.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.

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 picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bedevere-app

bedevere-app Bot commented Jul 4, 2026

Copy link
Copy Markdown

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 have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@picnixz picnixz closed this Jul 4, 2026
@picnixz

picnixz commented Jul 4, 2026

Copy link
Copy Markdown
Member

I'm closing it in advance but each PR should focus on its own purpose.

@picnixz

picnixz commented Jul 4, 2026

Copy link
Copy Markdown
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

concurrent.interpreters.Queue.get()/put() mishandle the timeout argument

2 participants