This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2019-08-06 01:20 by GeeTransit, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg349093 - (view) Author: George Zhang (GeeTransit) * 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.
History
Date User Action Args
2022-04-11 14:59:18adminsetgithub: 81952
2021-03-06 17:47:09graingertsetnosy: + alex.gronholm, graingert
2019-08-06 13:40:48GeeTransitsetversions: + Python 3.9
2019-08-06 01:38:01nanjekyejoannahsetnosy: + yselivanov
2019-08-06 01:20:30GeeTransitcreate