Pausing with Tornado a Genator Based Interface
Join the DZone community and get the full member experience.Join For Free
import tornado.web import tornado.ioloop from tornado import gen class MyHandler(tornado.web.RequestHandler): @tornado.web.asynchronous @gen.engine def get(self): self.write("sleeping .... ") # Do nothing for 5 sec yield gen.Task(loop.add_timeout, time.time() + 5) self.write("I'm awake!") self.finish()
Simple once you see it, but for some reason this has been the hardest for me to get used to.
Published at DZone with permission of A. Jesse Jiryu Davis, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.