Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Pausing with Tornado a Genator Based Interface

DZone's Guide to

Pausing with Tornado a Genator Based Interface

· Web Dev Zone ·
Free Resource

Bugsnag monitors application stability, so you can make data-driven decisions on whether you should be building new features, or fixing bugs. Learn more.

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):
    @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.

Monitor application stability with Bugsnag to decide if your engineering team should be building new features on your roadmap or fixing bugs to stabilize your application.Try it free.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}