The send
and next
functions are not features of Tornado, they are part of core Python. For more details see PEP 342 and this section of the official documentation.
You can write your own coroutines without tornado like so:
>>> def f():
... x = 0
... while True:
... x = x*2
... x = yield x
...
>>> coro = f()
>>> coro.next() #need to call 'next' once to start the coroutine
0
>>> coro.send(10)
20
>>> coro.send(100)
200
>>> coro.send(1000)
2000
>>>
The thing that tornado provides is an "event loop" which allows you to run a bunch of coroutines in a single process to achieve concurrency when there is blocking IO. For example in a web server that is reading data from a database and streaming the results to clients, each request will run in a separate coroutine, and tornado will handle the execution of all those coroutines concurrently by using yield/send/next at the points where IO occurs.