Skip to content

Instantly share code, notes, and snippets.

@cjgiridhar
Created September 17, 2014 05:35
Show Gist options
  • Save cjgiridhar/3ac7550dba96fd526c2f to your computer and use it in GitHub Desktop.
Save cjgiridhar/3ac7550dba96fd526c2f to your computer and use it in GitHub Desktop.
Tornado Async Example
import tornado.ioloop
from tornado.httpclient import AsyncHTTPClient
def handle_request(response):
'''callback needed when a response arrive'''
if response.error:
print("Error:", response.error)
else:
print('called')
print(response.body)
http_client = AsyncHTTPClient() # we initialize our http client instance
http_client.fetch("http://ip.jsontest.com", handle_request) # here we try
# to fetch an url and delegate its response to callback
print("Before Event Loop Starts!")
tornado.ioloop.IOLoop.instance().start() # start the tornado ioloop to
# listen for events
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment