python / python/cpython

Pure Python `SimpleQueue.get()` raises `ValueError` when block is false and timeout is given

Open
#156,476 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

The docs for SimpleQueue.get() say that timeout is ignored when block is false. The C version does that, but the pure Python version passes timeout to threading.Semaphore.acquire() and fails:

>>> from queue import _PySimpleQueue
>>> _PySimpleQueue().get(block=False, timeout=1)
Traceback (most recent call last):
  ...
ValueError: can't specify timeout for non-blocking acquire

The C version raises Empty here.

A PR is on the way.

Linked PRs
  • gh-156477
  • gh-156487
  • gh-156488
  • gh-156489

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the pure Python _PySimpleQueue.get() implementation and compare its handling of block=False and timeout with the C version and the SimpleQueue documentation. Done means a non-blocking get with a supplied timeout follows the documented behavior and raises Empty rather than ValueError; check the existing behavior shown in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.