? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details.
In [1]: c = 0
In [2]: def simple_core(): ...: global c ...: print('start c:', c) ...: c = yield (2+4) ...: print('end c:', c) ...:
In [3]: from inspect import getgeneratorstate
In [4]:
In [4]: my_coro = simple_core()
In [5]: getgeneratorstate(my_coro) Out[5]: 'GEN_CREATED'
In [6]: my_coro Out[6]: <generator object simple_core at 0x7f76f7cfff10>
In [7]: print(c) 0
In [8]: next(my_coro) start c: 0 Out[8]: 6
In [9]: print(c) 0
In [10]: getgeneratorstate(my_coro) Out[10]: 'GEN_SUSPENDED'
In [11]: my_coro.send(12) end c: 12
StopIteration Traceback (most recent call last) <ipython-input-11-2fa1746a2192> in <module>() ----> 1 my_coro.send(12)
StopIteration:
In [12]: In [7]: next(my_coro) ('start c:', 0) Out[7]: 5
In [8]: c Out[8]: 0
In [9]: my_coro.send(12) ('end c:', 12)
StopIteration Traceback (most recent call last) <ipython-input-9-2fa1746a2192> in <module>() ----> 1 my_coro.send(12)
StopIteration:
In [10]: