Message333861
The `inspect` module does not contain functions for determining the current state of asynchronous generators. That is, there is no introspection API for asynchronous generators that match the API for generators and coroutines: https://docs.python.org/3.8/library/inspect.html#current-state-of-generators-and-coroutines.
I propose to add `inspect.getasyncgenstate` and `inspect.getasyncgenlocals` (following `inspect.isasyncgenfunction` and `inspect.isasyncgen`).
% ./python
Python 3.8.0a0 (heads/fix-issue-getasyncgenstate:a24deae1e2, Jan 17 2019, 11:44:45)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect
>>> async def agen():
... x = 1
... yield x
... x += 1
... yield x
...
>>> ag = agen()
>>> inspect.getasyncgenstate(ag)
'AGEN_CREATED'
>>> inspect.getasyncgenlocals(ag)
{}
>>> ag.__anext__().__next__()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration: 1
>>> inspect.getasyncgenstate(ag)
'AGEN_SUSPENDED'
>>> inspect.getasyncgenlocals(ag)
{'x': 1}
>>> ag.__anext__().__next__()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration: 2
>>> inspect.getasyncgenstate(ag)
'AGEN_SUSPENDED'
>>> inspect.getasyncgenlocals(ag)
{'x': 2}
>>> ag.aclose().send(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
>>> inspect.getasyncgenstate(ag)
'AGEN_CLOSED'
>>> inspect.getasyncgenlocals(ag)
{} |
|
Date |
User |
Action |
Args |
2019-01-17 12:34:51 | tkren | set | recipients:
+ tkren |
2019-01-17 12:34:49 | tkren | set | messageid: <1547728489.52.0.471681525673.issue35759@roundup.psfhosted.org> |
2019-01-17 12:34:49 | tkren | link | issue35759 messages |
2019-01-17 12:34:49 | tkren | create | |
|