[Twisted-Python] Deferred.setTimeout is deprecated, replacement ideas?
gabriel.rossetti at arimaz.com
Wed Jul 16 05:00:11 EDT 2008
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)
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?
More information about the Twisted-Python