Possible lost notification in threading.Condition when a waiter times out

未关闭
#160,414 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

Start by reading threading.Condition in Lib/threading.py and its tests under Lib/test; the report concerns timeout handling when multiple waiters share a condition and notify(1) is called. Reproduce the two-waiter timing scenario, then check whether a notification can be consumed after a waiter's timeout. Done means the behavior is clarified or corrected and covered by a regression test; the issue links PR 160503.

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

描述

extension-modules type-bug
Bug report

Hi,

I noticed some unexpected behavior while testing threading.Condition on Python 3.14.4.

I created two threads waiting on the same condition. The first thread has a short timeout, while the second has a longer timeout. I then held the condition lock until the first waiter's timeout expired and called notify(1).

In my test, both wait() calls returned False, even though I called notify(1) while two waiters were still present in the internal wait queue. I observed the same result in 100 consecutive runs.

I'm not sure whether this is expected behavior or a race condition in how timed-out waiters are handled. Could someone clarify whether this behavior is expected? If not, it may be possible for a notification to be consumed by a waiter whose timeout has already expired, leaving another waiter waiting until its own timeout.

I can provide the minimal reproduction script and terminal output to help investigate.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs
  • gh-160503
主要语言
Python
星标
77.8k
派生
37.7k
平均合并
17 小时 24 分钟
30 天内合并 PR
716

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

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

python/cpython 的其他 Issue

查看 python/cpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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