[New-bugs-announce] [issue40607] asyncio.wait_for should reraise future exception even if timeout expires

Roman Skurikhin report at bugs.python.org
Tue May 12 07:33:07 EDT 2020


New submission from Roman Skurikhin <roman.skurikhin at cruxlab.com>:

In https://bugs.python.org/issue32751 asyncio.wait_for behaviour was changed that when we use timeout=... and the timeout expires, it waits until task is canceled. However, in some cases inner task can trigger exception while it handles cancellation. Check the following code:


import asyncio


async def ignore_cancel_and_raise():
    try:
        await asyncio.sleep(20)
    except asyncio.CancelledError:
        raise Exception('Cancellation failed')


async def main():
    try:
        await asyncio.wait_for(ignore_cancel_and_raise(), timeout=1)
    except asyncio.TimeoutError:
        print('Timeout')

asyncio.run(main())


It will print "Timeout" and log a warning that "Task exception was never retrieved".

I think that in case inner task cancelation fails with some error, asyncio.wait_for should reraise it instead of silently losing it.

----------
components: asyncio
messages: 368723
nosy: Roman Skurikhin, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.wait_for should reraise future exception even if timeout expires
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40607>
_______________________________________


More information about the New-bugs-announce mailing list