Last active
February 15, 2017 09:11
-
-
Save shyal/96ce8e9e721d6a0bc5a9484240b185c7 to your computer and use it in GitHub Desktop.
This example shows how to use the tornado AsyncHTTPClient concurrently to perform multiple gets
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
from tornado import gen, web, ioloop, httpclient | |
import json | |
class MainHandler(web.RequestHandler): | |
@gen.coroutine | |
def get(self): | |
http_client = httpclient.AsyncHTTPClient() | |
time, ip, headers = yield [http_client.fetch("http://time.ioloop.io?format=json"), | |
http_client.fetch("http://ip.ioloop.io?format=json"), | |
http_client.fetch("http://headers.ioloop.io?format=json")] | |
self.write({ | |
"time": json.loads(time.body), | |
"ip": json.loads(ip.body), | |
"headers": json.loads(headers.body) | |
}) | |
app = web.Application([("/", MainHandler)], debug=True) | |
app.listen(8888) | |
ioloop.IOLoop.current().start() |
Author
shyal
commented
Feb 14, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment