[New-bugs-announce] [issue37771] No equivalent of `inspect.getcoroutinestate` for PyAsyncGenASend instances

GeeVye report at bugs.python.org
Mon Aug 5 21:20:30 EDT 2019


New submission from GeeVye <geetransit at gmail.com>:

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.

----------
components: Demos and Tools
messages: 349093
nosy: GeeVye
priority: normal
severity: normal
status: open
title: No equivalent of `inspect.getcoroutinestate` for PyAsyncGenASend instances
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37771>
_______________________________________


More information about the New-bugs-announce mailing list