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
On 2012-08-20 07:34, Erik Forsberg wrote:
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?
After some experiments, I think I can answer my own question: * If you're using a callLater to deferred.cancel only, regardless of cause of the timout (connection timeout or request timeout), your errback will get ConnectingCancelledError. * If you use connectTimeout and a delayed call to deferred.cancel, and connectTimeout set to a lower value than the callback to deferred.cancel, you will get a TimeoutError in your errback if the connection times out. This allows you to distuingish between connection timeouts and request timeouts. Regards, \EF
On Aug 19, 2012, at 10:34 PM, Erik Forsberg <forsberg@opera.com> wrote:
I'm a little confused on how to use #4330.
The best way to use it would be to help get it merged to trunk and integrated into a release :). It looks like it's awaiting some patches to deal with review feedback at this point. Perhaps you could attach those to the ticket? -glyph
participants (2)
-
Erik Forsberg
-
Glyph