Extending Tornado.gen.task
Here's the interesting bits of a stupid websocket clock: class StupidClock(websocket.WebSocketHandler): clients = {} @web.asynchronous @gen.coroutine def open(self
Solution 1:
When you call yield gen.Callback
it briefly transfers control to Tornado, but Tornado immediately returns to your code. It's just a way to communicate with the coroutine scheduler without using global (or thread-local) variables. It uses this weird pattern so it can work with libraries that predated the gen
module and don't know anything about coroutines. For newer code (since Tornado 3.0), the recommended pattern has been for asynchronous functions to return a Future
(which happens automatically if you use @gen.coroutine
), which lets them be used in coroutines without gen.Task
or gen.Callback
.
Post a Comment for "Extending Tornado.gen.task"