python / python/cpython

asyncio eager tasks have no awaited_by edge during their first step

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

还没有人认领这个 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 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

把新 issue 发到你的邮箱

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