-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
async generator missing unawaited coroutine warning #89091
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
demo program:
output:
expected:
|
This is interesting! Currently no warning is raised for @gvanrossum What do you think about raising a |
Alas, my brain locks up when I start thinking about async generators. Maybe @1st1 can help? |
The implementation is simple, all we need is a finalizer to check if the current |
Can you get a 2nd opinion on that from a mailing list or forum? IIRC there's an async-sig still. |
My concern is that this might start warning for code that is totally harmless. Therefore I would definitely not backport any fix to 3.11 or before. |
It is not harmless, the code does nothing if it is not awaited and currently it doesn't even emit RuntimeWarning. |
@graingert Would you post this to discourse as Guido said for discussion? |
https://discuss.python.org/t/async-generator-missing-unawaited-coroutine-warning/17563/2 done Btw being tagged in the Nosy doesn't seem to subscribe me to issues |
Yeah, this is a pretty simple issue. Conceptually the |
Okay, I'll unsub this issue and you all can figure it out. |
I have hit this again today, I'll fix it in 3.13. |
Is this right solution to the problem of "lost" async generators? Can we pause and ask why this such a problem in the first place? Trying to improve the performance of async code is a challenge due to the layers of C code between the sender and the coroutine. It is can be worked around, but it is making more work for us trying to speed up async code. We added a big speedup for iterating over generators in 3.12. Doing the same for async generators is much harder due to the extra machinery. Adding more machinery is going to make it harder still. This is a more general problem than this particular issue, but I'd rather not make the situation any worse. |
The problem isn't "lost" async generators but its unawaited methods like
I don't see what better syntax would fix here, it is a user experience thing, and I have hit this issue multiple times.
I don't see how adding warning for this would stop any optimization. You probably want to optimize iteration by FYI this already exists for coroutines so this isn't a new thing being added. |
Do these methods get called directly often, rather than using
Because your PR adds a finalizer, it means that the destruction of the async generator's If you have a design for an optimization where that isn't a problem, I'd be happy to review it. |
I don't think that eliding the creation and destruction of the Ditto for Note again that All in all, I think there's not much worry in the next few releases about these particular objects getting in the way of optimization; and if they eventually do, well, then we may have to decide to downgrade the user experience slightly, to once again match the experience in 3.12 and before. Until then, I think it's nice to warn users when they forget to call |
Implemented in #104611 |
The warning shows up when you |
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:
Linked PRs
RuntimeWarning
for unawaited async generator methods #104611The text was updated successfully, but these errors were encountered: