Skip to content

Instantly share code, notes, and snippets.

@nhumrich
Last active August 19, 2018 04:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhumrich/c0ee81ddc3127fce21b674bfa996b2aa to your computer and use it in GitHub Desktop.
Save nhumrich/c0ee81ddc3127fce21b674bfa996b2aa to your computer and use it in GitHub Desktop.
async blog tornado example
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