Created
September 17, 2014 05:35
-
-
Save cjgiridhar/3ac7550dba96fd526c2f to your computer and use it in GitHub Desktop.
Tornado Async 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 | |
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