Issue #10220: Add inspect.getgeneratorstate(). Initial patch by Rodolpho Eckhardt
diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst
index 9a068da..810a95b 100644
--- a/Doc/library/inspect.rst
+++ b/Doc/library/inspect.rst
@@ -620,3 +620,25 @@
            # in which case the descriptor itself will
            # have to do
            pass
+
+Current State of a Generator
+----------------------------
+
+When implementing coroutine schedulers and for other advanced uses of
+generators, it is useful to determine whether a generator is currently
+executing, is waiting to start or resume or execution, or has already
+terminated. func:`getgeneratorstate` allows the current state of a
+generator to be determined easily.
+
+.. function:: getgeneratorstate(generator)
+
+    Get current state of a generator-iterator.
+
+    Possible states are:
+      GEN_CREATED: Waiting to start execution.
+      GEN_RUNNING: Currently being executed by the interpreter.
+      GEN_SUSPENDED: Currently suspended at a yield expression.
+      GEN_CLOSED: Execution has completed.
+
+
+
diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst
index 1bad544..dd47129 100644
--- a/Doc/whatsnew/3.2.rst
+++ b/Doc/whatsnew/3.2.rst
@@ -554,6 +554,14 @@
   (Contributed by R. David Murray, :issue:`10321`.)
 
 
+* The :mod:`inspect` module has a new function :func:`getgenatorstate`
+  to easily identify the current state of a generator as one of
+  ``GEN_CREATED``, ``GEN_RUNNING``, ``GEN_SUSPENDED`` or ``GEN_CLOSED``.
+
+  (Contributed by Rodolpho Eckhardt and Nick Coghlan, :issue:`10220`.)
+
+.. XXX: Mention inspect.getattr_static (Michael Foord)
+
 Multi-threading
 ===============