Created
September 27, 2012 21:53
-
-
Save kzahel/3796677 to your computer and use it in GitHub Desktop.
nested async yield
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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