Skip to content

asyncio: initial exception traceback frames are lost for Future.result() #154791

Description

@iaroslavkrasikov

Since gh-90082 (PR #30274), the C implementation of Future stores it's exception and traceback separately. However, Future.result() clears the traceback after first call, which means the initial traceback frames are lost on subsequent awaits or result() calls. Pure-python Future implementation is unaffected.

async def fail():
    await asyncio.sleep(0.1)
    1 / 0

async def main():
    task = asyncio.create_task(fail())
    await asyncio.sleep(0.2)
    with contextlib.suppress(ZeroDivisionError):
        await task
    await task

_CFuture traceback (current):

Traceback (most recent call last):
  ...
  File "<python-input-0>", line 9, in main
    await task
ZeroDivisionError

_PyFuture traceback (expected):

Traceback (most recent call last):
  ...
  File "<python-input-7>", line 9, in main
    await task
  ...
  File "<python-input-7>", line 3, in fail
    1 / 0
ZeroDivisionError

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions