`asyncio.print_call_graph()` loses the call stack at asynchronous generators
未關閉
還沒有人認領這個 Issue。
stdlib
topic-asyncio
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- 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 鏈,並將其輸出與預期的堆疊進行比較。當輸出保留非同步產生器以下的 frame 時,即表示完成;連結的 PR gh-156984 表示相關工作已經在進行中。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- devtools
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100