I’m using tornado to fetch many web pages asyncroniously using HTTP proxy. So, many of my fetch’es done with errors (my proxies are unreliable). I want to retry them instantly with another proxy. Here is example:
from tornado import ioloop
from tornado import httpclient
def handle_request(response):
if response.error:
print "Error:", response.error
// HERE i want to put my retry with another proxy
else:
print response.body
ioloop.IOLoop.instance().stop()
http_client = httpclient.AsyncHTTPClient()
http_client.fetch("http://www.google.com/", handle_request)
ioloop.IOLoop.instance().start()
But how i can i add new fetch event to current loop from handle_request ? Also, how can i pass variables to handle_request (list with all my proxies).
You’re asking two questions –
I would consider the use of partials http://docs.python.org/library/functools.html#partial-objects
The other choice of course is to make it an object.