Created
April 2, 2010 13:32
-
-
Save leadernux/353138 to your computer and use it in GitHub Desktop.
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.httpclient | |
import tornado.ioloop | |
def handle_response(to_write, response): | |
if response.error: | |
print "Error: ", response.error | |
else: | |
to_write = response.body | |
google_write = "" | |
yahoo_write = "" | |
http_client = tornado.httpclient.AsyncHTTPClient(); | |
http_client.fetch("http://google.com",lambda response: handle_response(google_write,response)); | |
http_client.fetch("http://yahoo.com",lambda response: handle_response(yahoo_write,response)); | |
ioloop.IOLoop.instance().start(); |
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
# -*- coding: utf-8 -*- | |
import tornado.httpclient | |
import tornado.ioloop | |
url_list, url_body = ["http://www.google.com","http://www.yahoo.com"], {} | |
http_client = tornado.httpclient.AsyncHTTPClient(); | |
def all_call_completes(): print(url_body) | |
if len(url_list) > 0: | |
x = 0 | |
def next_client(response, url_body, url_list, x, complete_callback): | |
if not response.error: url_body[url_list[x]] = response.body | |
if len(url_list)-1 == x: complete_callback() | |
else: http_client.fetch(url_list[x+1], | |
lambda response: | |
next_client(response, url_body, url_list, x+1, complete_callback)) | |
http_client.fetch(url_list[x],lambda response: next_client(response, url_body, url_list, x, all_call_completes)); | |
tornado.ioloop.IOLoop.instance().start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment