[Twisted-Python] deferreds and hung connections

Lenny G Arbage alengarbage at yahoo.com
Wed Mar 9 12:28:49 EST 2005


Suppose I am using twisted.web.client.getPage() to
retrieve webpages.  I am setting a callback and an
errback for the result, and this all works
fantastically.

But what about the case where the webserver simply
hangs with the connection open, never returning with
either a result or an error?

I assume that my errback will get called if the socket
times out and closes (right?).  But what if I don't
want to wait that long -- what if I want to do my own
timeout after N seconds/minutes?

I've been looking for examples of how to do this, and
monkeying with reactor.callLater() with partial
success.  If I save the id from callLater(), I can
cancel the timeout in callback() or errback(). 
However, if the timeout does get fired, I get:

[Failure instance: Traceback:
twisted.internet.error.AlreadyCalled, Tried to cancel
an already-called event.
/usr/lib/python2.3/site-packages/twisted/internet/defer.py:338:_runCallbacks
/tmp/deferred2.py:21:errback
/usr/lib/python2.3/site-packages/twisted/internet/base.py:82:cancel
]

Am I going about this the wrong way?  Perhaps twisted
has some built-ins that I'm not aware of to do
essentially the same thing?

I have a modified example from the Defer Howto that
exhibits this behavior.  I can post if the above
explanation isn't enough.

    thanks,
    Lenny


	
		
__________________________________ 
Celebrate Yahoo!'s 10th Birthday! 
Yahoo! Netrospective: 100 Moments of the Web 
http://birthday.yahoo.com/netrospective/




More information about the Twisted-Python mailing list