-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
asyncio blocks custom BaseException exceptions #108711
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
Comments
I'm not entirely sure what behavior you expected. Can you describe the bug in terms of what you expected vs. what actually happened? And can you tell us in which Python version this changed? Is it new in 3.11? Finally, the issue you link to has several PRs associated with it. Which of those PRs do you think is the cause of the change in behavior? |
Sorry about that. Let's see if I can make things more clear.
For the loop to stop. I.e. The de facto¹ standard has been that you derive from ¹ I would appreciate it if Python could document this stronger. I.e. that
It started in Python 3.8. To be clear, we have not yet encountered a real problem with this in asyncio. But it takes a long time for Python changes to propagate out to all distributions, so we want to be proactive when we see something that looks like it can cause issues for us down the line.
My apologies. I followed things back from the commit and didn't notice that the issue had multiple PR. It's PR #13528. I.e. changing this: except Exception: to except (SystemExit, KeyboardInterrupt):
raise
except BaseException: This gives The PR even mentions an approach that looks more appropriate to me: except (Exception, asyncio.CancelledError): |
The change is considered a feature. Previously, raising a base exception could violate internal invariants of the event loop machinery, because the event loop would only catch plain If you want to stop the event loop, use |
Bug report
Checklist
and am confident this bug has not been reported before
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.11.4 (main, Jun 7 2023, 00:00:00) [GCC 13.1.1 20230511 (Red Hat 13.1.1-2)]
A clear and concise description of the bug:
Since bpo-32528, this code no longer works:
I think this behaviour is very surprising as the general behaviour of exceptions based on
BaseException
is that they propagate over error handling. Currently, we'd need to do something hacky like inherit fromSystemExit
instead, basically relegatingBaseException
to something internal.This issue was mentioned in the PR, and supposed to be adjusted for Python 3.9:
#13528 (review)
Unfortunately, it seems that was forgotten.
The text was updated successfully, but these errors were encountered: