Hi there! I'm new in twisted, sorry if my question are stupid. I want to make tones of http get's to different urls and measure time for every request. I have tryed to use client.HTTPClientFactory for it, but it wants url as argument and i whink it's wrong to make a factory for every url. So, am i wrong? What class i must use for my needs? __ Regards, Sergey.
Hi Sergey, Several points: 1. Making a new factory for each *client* connection isn't unusual -- just for servers. 2. The API you probably want to use is twisted.web.client.Agent. 3. You could do something like this (I wrote no tests for this!) def timeURL(agent, url): return agent.get(url).addCallback(_responseReceived, time.time(), url) def _responseReceived(response, startTime, url): elapsed = time.time() - startTime print "Elapsed for {}: {}s".format(url, elapsed) # Note: response received gets called before the entire body is received ... or you could wrap that startTime and URL state in an object, of course :-) hope to help lvh
participants (2)
-
Laurens Van Houtven
-
Sergey Alembekov