-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Async generator might re-throw GeneratorExit on aclose() #79590
Comments
As far as I can tell, this issue is different than: https://bugs.python.org/issue34730 I noticed This seems to be related to a bug in Attached is a possible patch, although I'm not too comfortable messing with the python C internals. I can make a PR if necessary. |
I'm not sure this was the correct fix - or at least, this creates further issues with asynccontextmanager. Consider the following code: --------------- import contextlib
import types @contextlib.asynccontextmanager @types.coroutine
def _yield():
yield
async def func():
async with acm():
# GeneratorExit raised here
await _yield()
x = func()
x.send(None) # start running func
x.close() # raise GeneratorExit in func at its current yield
# AsyncContextManager __aexit__ fails with "RuntimeError: generator didn't stop after throw()" The reason for the failure in AsyncContextManager __aexit__ is that the asyncgenerator raises StopIteration instead of GeneratorExit when agen.athrow(GeneratorExit()) is called and driven, so "await agen.athrow(GeneratorExit())" just evaluates to None, rather than raising GeneratorExit. On 3.6 this would work fine, because "await athrow(GeneratorExit())" will raise GeneratorExit. I suspect this was broken by this change. |
My mistake, I see now this is just https://bugs.python.org/issue33786 and is already fixed. |
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: