Over a million developers have joined DZone.
Platinum Partner

Pausing with Tornado a Genator Based Interface

The Web Dev Zone is brought to you in partnership with Mendix.  Discover how IT departments looking for ways to keep up with demand for business apps has caused a new breed of developers to surface - the Rapid Application Developer.

Throwing this in my blog so I don’t forget again. The way to sleep for a certain period of time using tornado.gen is:

import tornado.web
import tornado.ioloop
from tornado import gen

class MyHandler(tornado.web.RequestHandler):
    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!")

Simple once you see it, but for some reason this has been the hardest for me to get used to.

The Web Dev Zone is brought to you in partnership with Mendix.  Learn more about The Essentials of Digital Innovation and how it needs to be at the heart of every organization.


Published at DZone with permission of A. Jesse Jiryu Davis , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}