-
Notifications
You must be signed in to change notification settings - Fork 150
return in finally swallows exceptions #816
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
Note to self: this can be found in |
this now also gives a |
This is in contributed code and I've looked at it a couple times but didn't know what to make of it – that is, why it's there. Feel free to send a PR if you know how to deal with it. |
EDIT: ~all of this is wrong, I made some incorrect assumptions when testing It appears that the exception suppression is intended, otherwise this test fails anyio/tests/test_from_thread.py Lines 494 to 502 in 9c876b1
which was added in #191 But the test only checks for |
nvm what I said above, I did my testing in a bad way and confused different error suppression things. What #382 addressed was tl;dr, I propose doing the easy fix of moving try:
# Wait for the sync context manager to exit.
# This next statement can raise `get_cancelled_exc_class()` if
# something went wrong in a task group in this async context
# manager.
await self._exit_event.wait()
finally:
# In case of cancellation, it could be that we end up here before
# `_BlockingAsyncContextManager.__exit__` is called, and an
# `_exit_exc_info` has been set.
result = await self._async_cm.__aexit__(*self._exit_exc_info)
return result |
Things to check first
I have searched the existing issues and didn't find my bug already reported there
I have checked that my bug is still present in the latest release
AnyIO version
mater branch
Python version
NA
What happened?
In
anyio/src/anyio/from_thread.py
Line 119 in 3a62738
return
statement in afinally
block, which would swallow any in-flight exception.This means that if an unhandled exception (including a
BaseException
such asKeyboardInterrupt
) is raised from thetry
body, it will not propagate on as expected.If the intention is to suppress all exceptions, I would propose to make this clear by using
except BaseException
.See also https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions.
How can we reproduce the bug?
NA
The text was updated successfully, but these errors were encountered: