Skip to content

Instantly share code, notes, and snippets.

@cjgiridhar
Created September 17, 2014 06:04
Show Gist options
  • Save cjgiridhar/b8fde85a77249d0e538f to your computer and use it in GitHub Desktop.
Save cjgiridhar/b8fde85a77249d0e538f to your computer and use it in GitHub Desktop.
Tornado Gen Coroutine
import tornado.web
import tornado.gen
from tornado.httpclient import AsyncHTTPClient
class GenAsyncHandler(tornado.web.RequestHandler):
@tornado.gen.coroutine
def get(self):
http_client = AsyncHTTPClient()
response = yield http_client.fetch("http://ip.jsontest.com")
print(response)
application = tornado.web.Application([
(r"/", GenAsyncHandler),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment