Skip to content

Instantly share code, notes, and snippets.

@kzahel
Created September 27, 2012 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kzahel/3796677 to your computer and use it in GitHub Desktop.
Save kzahel/3796677 to your computer and use it in GitHub Desktop.
nested async yield
def asyncsleep(t, callback=None):
ioloop.add_timeout( time.time() + t, callback )
class NestedYieldAsync(tornado.web.RequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
def get(self):
yield gen.Task( self.lots_of_waits )
yield gen.Task( self.lots_of_waits )
self.finish()
@tornado.gen.engine
def lots_of_waits(self, callback=None):
for i in range(3):
print 'sleep',i
yield gen.Task( asyncsleep, 1 )
callback()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment