-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
anext_awaitable is not a collections.abc.Generator #89126
Comments
The anext_awaitable object returned by anext(..., default) does not support .send()/.throw(). It only supports __next__(). So we can pass messages from the suspending coroutine to the event loop but not from the event loop to the suspending coroutine. trio and curio rely on both directions working. (I don't know about asyncio.) For example, this trio code fails: import trio
async def produce():
for v in range(3):
await trio.sleep(1)
yield v
async def consume():
p = produce()
while True:
print(await anext(p, 'finished'))
trio.run(consume) raising AttributeError: 'anext_awaitable' object has no attribute 'send'. I realise that any awaitable that wants to await another awaitable must return not an iterator from __await__() but something that implements the full PEP-342 generator protocol. Should PEP-492 section on __await__()[1] say something about that? [1] https://www.python.org/dev/peps/pep-0492/#await-expression |
it also fails with asyncio.create_task
there's also a problem with cancelling and aclosing an async gen this way:
|
I am marking this as a release blocker, given that this is probably going to trip a lot of users. |
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: