Skip to content

Instantly share code, notes, and snippets.

@stevepeak
Created January 29, 2013 21:36
Show Gist options
  • Save stevepeak/4668126 to your computer and use it in GitHub Desktop.
Save stevepeak/4668126 to your computer and use it in GitHub Desktop.
tornado.gen.engine example
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