[Twisted-Python] Twisted Names Deprecation Warning Fixes
Andrew Bennetts
andrew-twisted at puzzling.org
Wed Mar 23 12:56:00 MST 2005
On Wed, Mar 23, 2005 at 05:49:47AM -0800, Peter Kropf wrote:
[...]
> @@ -1123,8 +1124,13 @@
> self.resends[id] = 1
> m = Message(id, recDes=1)
> m.queries = queries
> - d = self.liveMessages[id] = defer.Deferred()
> - d.setTimeout(timeout, self._clearFailed, id)
> +
> + from twisted.internet import reactor
> + d = defer.Deferred()
> + timeoutCall = reactor.callLater(
> + timeout,
> + lambda: d.called or self._clearFailed( d, id ) )
> + self.liveMessages[id] = ( d, timeoutCall )
> self.writeMessage(m, address)
> return d
I think this would be better as:
from twisted.internet import reactor
d = defer.Deferred()
timeoutCall = reactor.callLater(timeout, self._clearFailed, d, id)
def cancelTimeout(result, timeoutCall=timeoutCall):
timeoutCall.cancel()
return result
d.addBoth(cancelTimeout)
self.liveMessages[id] = ( d, timeoutCall )
'called' is not part of Deferred's public API.
-Andrew.
More information about the Twisted-Python
mailing list