Last active
August 19, 2018 04:42
-
-
Save nhumrich/c0ee81ddc3127fce21b674bfa996b2aa to your computer and use it in GitHub Desktop.
async blog tornado example
This file contains hidden or 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 | |
urls = ['http://www.google.com', 'http://www.yandex.ru', 'http://www.python.org'] | |
def handle_response(response): | |
if response.error: | |
print("Error:", response.error) | |
else: | |
url = response.request.url | |
data = response.body | |
print('{}: {} bytes: {}'.format(url, len(data), data)) | |
http_client = AsyncHTTPClient() | |
for url in urls: | |
http_client.fetch(url, handle_response) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment