python / python/cpython

asyncio eager tasks have no awaited_by edge during their first step

オープン
#157,299 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供された asyncio の再現コードを eager_task_factory で実行し、デフォルトの task factory と呼び出しグラフを比較します。レポートで説明されている eager start と awaited_by の登録を調査します。既存の動作を壊すことなく、最初の子ステップにその parent が “Awaited by” セクションに表示されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。