Python 3.5+inspectfunction
inspect.getcoroutinestate()
coroutines and generators
A coroutine's state as a string: CORO_CREATED, CORO_RUNNING, CORO_SUSPENDED or CORO_CLOSED.
Syntax
inspect.getcoroutinestate(coroutine)
A coroutine in CORO_CREATED is an async function that was called but never awaited; dropping it like that triggers the 'coroutine was never awaited' warning. The function expects a coroutine object, not the async function and not a generator: given a generator it fails with AttributeError, not TypeError. Use getgeneratorstate for generators and getasyncgenstate for async generators.
Examples
import inspect
class Pause:
def __await__(self):
yield
async def job():
await Pause()
c = job()
print(inspect.getcoroutinestate(c)) # → CORO_CREATED
c.send(None)
print(inspect.getcoroutinestate(c)) # → CORO_SUSPENDED
c.close()
print(inspect.getcoroutinestate(c)) # → CORO_CLOSED
See also
Open in the full glossarydocs.python.orgReport an inaccuracy