[Twisted-Python] How to deal with deferreds across several layers of namespaces?
itamar at futurefoundries.com
Fri Aug 17 20:12:25 EDT 2012
On Thu, Aug 16, 2012 at 3:42 PM, Idlecore <xor at idlecore.com> wrote:
> I have a protocol that calls code that spans several namespaces. At
> any of these namespaces there might be a deferred waiting to be
> called. The protocol can be disconnected at any time and I currently
> don't have a clean way to cancel all the potential deferreds from
> within the protocol.
What do you mean by "namespaces"? If the Protocol called some code that
returned a Deferred, the Protocol will then have a reference to it. If a
callback function on that Deferred returns a Deferred, cancelling the
original one will also cancel the chained Deferred if necessary (though
you'll need to have a cancellation function for each, of course).
> Will the protocol stick around long enough after disconnection for the
> deferreds to eventually be called?
The Protocol will have its connectionLost() method called when it
disconnects; this is where you'd typically cancel any pending operations.
If some other object has a reference to it, it will not be garbage
collected until that reference is gone, as with any Python object. The
pending operations will, however, continue (possibly wasting resources)
unless you cancel them in response to the connectionLost() call.
Can you give a tiny code example, perhaps, demonstrating the kind of
Deferred management problem you're having?
Itamar Turner-Trauring, Future Foundries LLC
http://futurefoundries.com/ — Twisted consulting, training and support.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python