Skip to content

asyncio.gather() records its creator instead of the actual awaiting task in the call graph #162061

Open

Description

@deadlovelll

Bug report

The call graph shows who created gather(), rather than who awaits it

Repro:

import asyncio


async def consume(future):
    await future


async def main():
    release = asyncio.Event()
    child = asyncio.create_task(release.wait(), name="child")
    wrapper = asyncio.gather(child)
    consumer = asyncio.create_task(consume(wrapper), name="consumer")
    await asyncio.sleep(0)

    asyncio.print_call_graph(child)

    release.set()
    await consumer


asyncio.run(main())

Actual:

* Task(name='child', id=0x1056cc7d0)
  + Call stack:
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/locks.py', line 210, in async Event.wait()
  + Awaited by:
    * Task(name='Task-1', id=0x1056cc5f0)
      + Call stack:
      |   File '/Users/timofeiivankov/cpython/repro.py', line 15, in async main()

The problem here that child is not awaited by the main, it's awaited by the gather which in his order is awaited by consumer. At the moment of the capturing call graph, no one of the tasks or futures is not awaited by main

Expected:

* Task(name='child', id=0x101b1c7d0)
  + Call stack:
  |   File '/Users/timofeiivankov/cpython/Lib/asyncio/locks.py', line 210, in async Event.wait()
  + Awaited by:
    * Future(id=0x1017b28d0)
      + Awaited by:
        * Task(name='consumer', id=0x101b003f0)
          + Call stack:
          |   File '/Users/timofeiivankov/cpython/repro.py', line 5, in async consume()

Proposed fix: link children to the future returned by gather() instead of the task that created it

Problem: fix can be applied, but tests for the remote_debugging will fail, i already created #161508 for supportig Futures here, since it will be merged to main i'll be able to work on this issue

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Activity

  1. Abhi210 commented on Nov 16, 2026

    @Abhi210
    Contributor

    I will work on this.

  2. deadlovelll commented on Nov 16, 2026

    @deadlovelll
    ContributorAuthor

    I will work on this.

    Hi! In the body of issue i wrote, since the blocker will disappear, i will work on this issue =)

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

    Projects

    • Status
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions