[Twisted-Python] Deferred.setTimeout is deprecated, replacement ideas?

Gabriel Rossetti gabriel.rossetti at arimaz.com
Wed Jul 16 05:22:09 EDT 2008

Gabriel Rossetti wrote:
> Hello everyone,
> I was going to use Deferred.setTimeout until I saw that it was 
> deprecated. Does anyone know why? I found it handy and I find that 
> case-per-case replacements tend to be complicated. Does anyone have 
> any ideas on how to replace it?
> I have a queue containing read results from I/O, the get() method 
> returns a deferred fired when the data arrives (sort of like 
> defer.DeferredQueue). Since I need to be able to set a read timeout, 
> i.e. if the data doesn't arrive after a certain time, I need to raise 
> an exception and remove the deferred from the internal list; the 
> defer's timeout would have been handy here :-(.
> I was thinking of doing something like this, if data isn't present in 
> the data internal list:
> d = Deferred()
> dc = reactor.callLater(self.timeout, self.__timeoutCallback, d)
> d.addCallback(self.__timeoutCanceller)
> Then a tuple containing the Deferred ("d"), the DelayedCall ("dc") is 
> then put in the internal waiting list. If the timeout doesn't expire 
> before the data arrives, then the DelayedCall is canceled, if it does 
> expire then the tuple is removed from the queue (potentially slow) and 
> an exception is raised.
> Is there a better way of doing this? Any ideas?
> Thank you,
> Gabriel
I can remove the "d.addCallback(self.__timeoutCanceller)" call since the 
DelayedCall can be canceled by the code that does the waiting list 

More information about the Twisted-Python mailing list