[Twisted-web] Timeouts on Agent requests

Erik Forsberg forsberg at opera.com
Mon Aug 20 01:34:39 EDT 2012


I'm thinking about using Twisted as a http client, talking to some 
rather uncooperative servers that sit on the other side of some really 
crappy parts of the internet. So I need timeouts.

I was looking into t.w.c.Agent, and see that it has a connect timeout 
option, which is good, but lacks request timeouts. Then found 
http://twistedmatrix.com/trac/ticket/4330 which looks like a solution.

I'm a little confused on how to use #4330. Would something like this be 

def main():
     agent = Agent(reactor)
     deferred = agent.request('HEAD', url)
     cancel = reactor.callLater(30, deferred.cancel)

def handle_request(response):
     <handle response>

def handle_errors(failure):
     <see if failure is CanceledError>

Will this also automatically give me a connection timeout, or should I 
give Agent's constructor connectTimeout as argument and handle that in 
handle_errors too?

I might have totally misunderstood the whole thing too, as I'm a bit new 
to Twisted.


More information about the Twisted-web mailing list