summaryrefslogtreecommitdiffstats
path: root/Doc/library/inspect.rst
diff options
context:
space:
mode:
authorThomas Krennwallner <tk@postsubmeta.net>2023-03-11 13:19:40 (GMT)
committerGitHub <noreply@github.com>2023-03-11 13:19:40 (GMT)
commitced13c96a4eb9391a9d27e3e13218f70c579670f (patch)
tree2e48fbdb4e1539ae821c5b3ac0a7a70e6d1fbf93 /Doc/library/inspect.rst
parentaa0a73d1bc53dcb6348a869df1e775138991e561 (diff)
downloadcpython-ced13c96a4eb9391a9d27e3e13218f70c579670f.zip
cpython-ced13c96a4eb9391a9d27e3e13218f70c579670f.tar.gz
cpython-ced13c96a4eb9391a9d27e3e13218f70c579670f.tar.bz2
gh-79940: add introspection API for asynchronous generators to `inspect` module (#11590)
Diffstat (limited to 'Doc/library/inspect.rst')
-rw-r--r--Doc/library/inspect.rst28
1 files changed, 26 insertions, 2 deletions
diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst
index 789e983..ccf2401 100644
--- a/Doc/library/inspect.rst
+++ b/Doc/library/inspect.rst
@@ -1440,8 +1440,8 @@ code execution::
pass
-Current State of Generators and Coroutines
-------------------------------------------
+Current State of Generators, Coroutines, and Asynchronous Generators
+--------------------------------------------------------------------
When implementing coroutine schedulers and for other advanced uses of
generators, it is useful to determine whether a generator is currently
@@ -1476,6 +1476,22 @@ generator to be determined easily.
.. versionadded:: 3.5
+.. function:: getasyncgenstate(agen)
+
+ Get current state of an asynchronous generator object. The function is
+ intended to be used with asynchronous iterator objects created by
+ :keyword:`async def` functions which use the :keyword:`yield` statement,
+ but will accept any asynchronous generator-like object that has
+ ``ag_running`` and ``ag_frame`` attributes.
+
+ Possible states are:
+ * AGEN_CREATED: Waiting to start execution.
+ * AGEN_RUNNING: Currently being executed by the interpreter.
+ * AGEN_SUSPENDED: Currently suspended at a yield expression.
+ * AGEN_CLOSED: Execution has completed.
+
+ .. versionadded:: 3.12
+
The current internal state of the generator can also be queried. This is
mostly useful for testing purposes, to ensure that internal state is being
updated as expected:
@@ -1507,6 +1523,14 @@ updated as expected:
.. versionadded:: 3.5
+.. function:: getasyncgenlocals(agen)
+
+ This function is analogous to :func:`~inspect.getgeneratorlocals`, but
+ works for asynchronous generator objects created by :keyword:`async def`
+ functions which use the :keyword:`yield` statement.
+
+ .. versionadded:: 3.12
+
.. _inspect-module-co-flags: