Created
January 29, 2013 21:36
-
-
Save stevepeak/4668126 to your computer and use it in GitHub Desktop.
tornado.gen.engine example
This file contains 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
import tornado.ioloop | |
import tornado.web | |
import tornado.gen | |
import tornado.httpclient | |
class GenAsyncHandler(tornado.web.RequestHandler): | |
@tornado.web.asynchronous | |
@tornado.gen.engine | |
def get(self): | |
http_client = tornado.httpclient.AsyncHTTPClient() | |
response = yield tornado.gen.Task(http_client.fetch, "http://example.com") | |
print response, dir(response) | |
print response.error | |
self.finish('Fin.') | |
application = tornado.web.Application([ | |
(r"/", GenAsyncHandler), | |
]) | |
if __name__ == "__main__": | |
application.listen(8889) | |
tornado.ioloop.IOLoop.instance().start() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment