`asyncio.print_call_graph()` loses the call stack at asynchronous generators
未关闭
还没有人认领这个 Issue。
stdlib
topic-asyncio
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
asyncio.print_call_graph() stops at the first async gen in the await chain and silently drops all of the call stack below it
Repro:
import asyncio
async def deep():
await asyncio.Event().wait()
async def producer():
await deep()
yield 1
async def consumer():
async for _ in producer():
pass
async def main():
t = asyncio.create_task(consumer(), name='consumer')
await asyncio.sleep(0.05)
print(asyncio.format_call_graph(t))
asyncio.run(main())
Expected:
* Task(name='consumer', id=0x105be89b0)
+ Call stack:
| File '/Users/timofeiivankov/cpython/Lib/asyncio/locks.py', line 210, in async Event.wait()
| File '/Users/timofeiivankov/cpython/repro.py', line 4, in async deep()
| File '/Users/timofeiivankov/cpython/repro.py', line 7, in async generator producer()
| File '/Users/timofeiivankov/cpython/repro.py', line 11, in async consumer()
Actual:
* Task(name='consumer', id=0x105b089b0)
+ Call stack:
| File '/Users/timofeiivankov/cpython/repro.py', line 11, in async consumer()
Proposed fix: expose the wrapped generator as ag_gen and step over the wrapper through it
Have a fix ready for that
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-156984
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 asyncio.format_call_graph() 和 issue 中的 reproducer 开始,包括异步生成器 producer() 和 consumer task。检查调用图如何遍历 await 链,并将其输出与预期的堆栈进行比较。当输出保留异步生成器以下的帧时,即表示完成;链接的 PR gh-156984 表明相关工作已经在进行中。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100