Platinum Partner
css,python,tornado

Pausing with Tornado a Genator Based Interface

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.

Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

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

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}