-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asyncio.wait_for should reraise future exception even if timeout expires #84787
Comments
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. |
Also adding Nathaniel since he's the one that filed bpo-32751. Nathaniel, do you agree that if an exception occurs while waiting for the cancellation, the exception should be what's raised instead of TimeoutError? |
makes sense to me On Tue, May 12, 2020 at 10:14 PM Chris Jerdonek <report@bugs.python.org> wrote:
|
+1. |
Thank you again, Roman and all. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: