there are several questions on stackoverflow regarding tornado I still haven't found out an answer to my question I have a big text file that I wish to iterate on and send each line as a POST http request. I wish to do it async ( I need it to be fast) and then check the responses of the requests.
I have something like that
http_client = httpclient.AsyncHTTPClient()
with open(filename) as log_file:
for line in log_file:
request = httpclient.HTTPRequest(self.destination,method="POST",headers=self.headers,body=json.dumps(line))
response = http_client.fetch(request, callback=self.handle_request)
looking at tcpdump this does not do anything all I get is a serious of "Futures" object I also tried placing the fetch command in "yield" and then iterating it while using the @gen.coroutine decorator on the method. that did not help. can anyone please tell me what am I doing wrong?
thanks!
Here's how you'd use "fetch" in a coroutine:
You can test this with a little server that receives the lines and prints them:
First run the server code, and then the client.
If you want to post up to 10 log lines at a time in parallel, install Toro and do: