example-code-2e/control/coro_simple_demo.rst
2015-02-02 02:56:14 -02:00

14 lines
282 B
ReStructuredText

>>> def coroutine():
... print('coroutine started')
... x = yield
... print('coroutine received: {!r}'.format(x))
...
>>> coro = coroutine()
>>> next(coro)
coroutine started
>>> coro.send(42)
coroutine received: 42
Traceback (most recent call last):
...
StopIteration