Timeouts on Agent requests

Erik Forsberg <[email protected]>
Newsgroups gmane.comp.python.twisted.web
Message-ID <[email protected]>
Hi!

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 
appropriate:

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

def handle_request(response):
     cancel.cancel()
     <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.

Thanks,
\EF
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.