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
Since gh-90082 (PR #30274), the C implementation of
Futurestores 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 orresult()calls. Pure-python Future implementation is unaffected._CFuturetraceback (current):_PyFuturetraceback (expected):Linked PRs