asyncio eager tasks have no awaited_by edge during their first step
未關閉
還沒有人認領這個 Issue。
stdlib
topic-asyncio
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
Task that created by eager task factory runs its first step before the awaited_by edge is registered. During this step the graph shows that this task is awaited by nobody
Repro:
import asyncio
async def child():
asyncio.print_call_graph()
await asyncio.sleep(0)
async def main():
await asyncio.gather(child())
loop = asyncio.new_event_loop()
loop.set_task_factory(asyncio.eager_task_factory)
loop.run_until_complete(main())
Expected:
* Task(name='Task-2', id=0x103544b90)
+ Call stack:
| File '/Users/timofeiivankov/cpython/repro.py', line 4, in async child()
+ Awaited by:
* Task(name='Task-1', id=0x103544d70)
+ Call stack:
| File '/Users/timofeiivankov/cpython/repro.py', line 8, in async main()
Actually:
* Task(name='Task-2', id=0x103058b90)
+ Call stack:
| File '/Users/timofeiivankov/cpython/repro.py', line 4, in async child()
With the default task factory it works fine as expected
Proposed fix: Register the edge inside the eager start and discard it when the step ends
I have a fix ready
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-157300
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
使用 eager_task_factory 執行提供的 asyncio 重現,並將其呼叫圖與預設 task factory 的呼叫圖進行比較。檢查報告中描述的 eager start 和 awaited_by 註冊;當第一個子步驟在「Awaited by」區段顯示其 parent,且不破壞現有行為時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100