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.timeout(0) and asyncio.timeout(-1) cancellation is delayed #95051
Comments
This also makes refactoring |
Sorry, deleted my last comment since it was wrong. I'm going to try to dive into this a little to get some understanding. |
This is a race condition. Two things need to happen on the same event loop iteration, but it turns out A happens before B, and not B before A. I don't think asyncio has a spec anywhere saying this is wrong, so a legitimate response might be to just live with it. Maybe it's confusing to users though so we want to do something about it. The event loop maintains two callback lists:
When processing a loop step, the event loop looks at
So this explains the issue:
A couple of proposals how to handle this: A. do nothing, leave it up to the event loop how to resolve cases like this My personal preference might be D, and then A. @gvanrossum I know you've been in this space recently, would appreciate your feedback. |
Bug report
I expect this to raise a TimeoutError:
Instead I have to add an extra
asyncio.sleep(0)
to get a TimeoutErrorYour environment
The text was updated successfully, but these errors were encountered: