Python 3.5+inspectfunction
inspect.getcoroutinelocals()
coroutines and generators
A dict of the current local variables of a suspended coroutine, the async def counterpart of getgeneratorlocals.
Syntax
inspect.getcoroutinelocals(coroutine)
Until the coroutine has been advanced the dict holds only its arguments; body variables appear as it runs, and after it finishes the dict is empty. Useful in tests that drive a coroutine by hand with send(None), without an event loop. Pass the coroutine object, not the async function itself.
Examples
import inspect
class Pause:
def __await__(self):
yield
async def job(n):
step = n * 2
await Pause()
c = job(5)
print(inspect.getcoroutinelocals(c)) # → {'n': 5} — пока только аргументы
c.send(None)
print(inspect.getcoroutinelocals(c)) # → {'n': 5, 'step': 10}
c.close()
See also
Open in the full glossarydocs.python.orgReport an inaccuracy