Skip to content

asyncio eager tasks have no awaited_by edge during their first step #157299

Description

@deadlovelll

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error

    Projects

    • Status
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions