-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
GH-117536: GH-117894: fix athrow().throw(...) unawaited warning #117851
Conversation
graingert
commented
Apr 13, 2024
•
edited
Loading
edited
- Issue: RuntimeWarning: coroutine method 'aclose' of '...' was never awaited when breaking out of async for #117536
- Issue: async generator aclose()/athrow() can be re-used after StopIteration #117894
ccf9830
to
da89a69
Compare
797e0d5
to
f1ac5d3
Compare
This also fixes a bug where an athrow()/aclose() can be reused across StopIteration calls, so needs backporting to 3.12 |
Here's the repro: >>> class MyExc(Exception): pass
...
>>> import itertools
>>> async def gen():
... for i in itertools.count():
... try:
... yield i
... except MyExc:
... pass
...
>>> agen = gen()
>>> agen.asend(None).send(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration: 0
>>> athrow = agen.athrow(MyExc)
>>> athrow.throw(MyExc)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration: 1
>>> athrow.throw(MyExc)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration: 2
>>> athrow.throw(MyExc)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration: 3
>>> athrow.throw(MyExc)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration: 4
>>> |
Misc/NEWS.d/next/Core and Builtins/2024-04-13-16-55-53.gh-issue-117536.xkVbfv.rst
Outdated
Show resolved
Hide resolved
Misc/NEWS.d/next/Core and Builtins/2024-04-13-16-55-53.gh-issue-117536.xkVbfv.rst
Outdated
Show resolved
Hide resolved
…e-117536.xkVbfv.rst
Misc/NEWS.d/next/Core and Builtins/2024-04-13-16-55-53.gh-issue-117536.xkVbfv.rst
Outdated
Show resolved
Hide resolved
Misc/NEWS.d/next/Core and Builtins/2024-04-13-16-55-53.gh-issue-117536.xkVbfv.rst
Outdated
Show resolved
Hide resolved
Misc/NEWS.d/next/Core and Builtins/2024-04-15-13-53-59.gh-issue-117894.8LpZ6m.rst
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not an expert in this area, but I cannot find anything wrong with the patch. An unhandled exception marking the awaitable closed (awaited) makes sense.
Let's merge this to fix the blocker issue. On #117882 I'll try to deepen my understanding of this code, so I can give a better review. |
This needs backporting to 3.12 |
Thanks @graingert for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry, @graingert and @encukou, I could not cleanly backport this to
|
GH-118226 is a backport of this pull request to the 3.12 branch. |