python / python/cpython

asyncio eager tasks have no awaited_by edge during their first step

Aperta
#157,299 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib topic-asyncio type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Esegui la riproduzione asyncio fornita con eager_task_factory e confronta il relativo grafo delle chiamate con quello della factory di task predefinita. Esamina l’eager start e la registrazione di awaited_by descritti nel report; il lavoro è completato quando il primo passaggio figlio mostra il proprio parent nella sezione “Awaited by” senza compromettere il comportamento esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.