python / python/cpython

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

未关闭
#156,476 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从纯 Python 的 _PySimpleQueue.get() 实现开始,将其对 block=False 和 timeout 的处理与 C 版本及 SimpleQueue 文档进行比较。当提供 timeout 的非阻塞 get 遵循文档规定的行为并引发 Empty 而不是 ValueError 时,即视为完成;检查 issue 中展示的现有行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
backend
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。