Author GeeVye
Recipients GeeVye
Date 2019-08-06.01:20:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1565054430.97.0.58176402921.issue37771@roundup.psfhosted.org>
In-reply-to
Content
In PEP 525, async generators were introduced. They use `.asend()` and `.athrow()` methods that return a "coroutine-like" object - specifically, a PyAsyncGenASend and PyAsyncGenAThrow respectively.

While these "coroutine-like" object implement `.send()`, `.throw()`, and `.close()`, they don't provide any attributes like normal coroutine objects do such as `cr_running` or `cr_await`.

When I use `inspect.getcoroutinestate()`, it raises an AttributeError on how there isn't a `cr_running` attribute / flag.

There is a workaround I use which is to wrap it with another coroutine as below:

>>> async def async_generator():
...     yield
...
>>> async def wrap_coro(coro):
...     return await coro
>>> agen = async_generator()
>>> asend = wrap_coro(agen.asend(None))

This seems like something that should be changed to make it more inline with normal coroutines / awaitables.
History
Date User Action Args
2019-08-06 01:20:31GeeVyesetrecipients: + GeeVye
2019-08-06 01:20:30GeeVyesetmessageid: <1565054430.97.0.58176402921.issue37771@roundup.psfhosted.org>
2019-08-06 01:20:30GeeVyelinkissue37771 messages
2019-08-06 01:20:30GeeVyecreate