-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Prevent double awaiting of async iterator #83567
Comments
If I create a coro from an async iterator, then wait_for it w/ a timeout, but shielded, so it won't get canceled, and then await upon it, it returns invalid data. See the attached test case. The reason I do the following is to make sure that an async iterator that I have written doesn't return data early, and needs to wait till later. If I didn't shield it, then the async iterator would get cancelled, and I don't want this. I'd expect either correct results to be returned, or an exception to be raised, but in this case, and the docs for wait_for ( https://docs.python.org/3/library/asyncio-task.html#asyncio.wait_for ), I'd expect the correct results to be returned. In the attached case, this is the results that I get: I do not have python 3.8 to test with. |
Thanks for the report. Your example could be boiled down to the following: coro = asynciter()
await coro
await coro The second call incorrectly returns None but should raise an exception, double awaiting is a programming error. For regular async functions it raises "RuntimeError: cannot reuse already awaited coroutine" |
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: