Title: No equivalent of `inspect.getcoroutinestate` for PyAsyncGenASend instances
Type: behavior Stage:
Components: Demos and Tools Versions: Python 3.9, Python 3.8
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: GeeVye, yselivanov
Priority: normal Keywords:

Created on 2019-08-06 01:20 by GeeVye, last changed 2019-08-06 13:40 by GeeVye.

Messages (1)
msg349093 - (view) Author: George Zhang (GeeVye) * Date: 2019-08-06 01:20
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.
Date User Action Args
2019-08-06 13:40:48GeeVyesetversions: + Python 3.9
2019-08-06 01:38:01nanjekyejoannahsetnosy: + yselivanov
2019-08-06 01:20:30GeeVyecreate