New submission from Thomas Krennwallner :
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 "", line 1, in
StopIteration: 1
>>> inspect.getasyncgenstate(ag)
'AGEN_SUSPENDED'
>>> inspect.getasyncgenlocals(ag)
{'x': 1}
>>> ag.__anext__().__next__()
Traceback (most recent call last):
File "", line 1, in
StopIteration: 2
>>> inspect.getasyncgenstate(ag)
'AGEN_SUSPENDED'
>>> inspect.getasyncgenlocals(ag)
{'x': 2}
>>> ag.aclose().send(None)
Traceback (most recent call last):
File "", line 1, in
StopIteration
>>> inspect.getasyncgenstate(ag)
'AGEN_CLOSED'
>>> inspect.getasyncgenlocals(ag)
{}
--
components: Library (Lib)
files: 0001-inspect-add-introspection-API-for-asynchronous-gener.patch
keywords: patch
messages: 333861
nosy: tkren
priority: normal
severity: normal
status: open
title: inspect module does not implement introspection API for asynchronous
generators
type: enhancement
versions: Python 3.8
Added file:
https://bugs.python.org/file48066/0001-inspect-add-introspection-API-for-asynchronous-gener.patch
___
Python tracker
<https://bugs.python.org/issue35759>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com