[Twisted-Python] understanding deferreds

Terry Jones terry at jon.es
Thu Jan 28 17:46:08 EST 2010

>>>>> "Michael" == Michael P Soulier <msoulier at digitaltorque.ca> writes:

Michael> I'm a bit confused as to the "visual explanation". It seems like
Michael> if you have a single callback and errback, that if the errback
Michael> wants to swallow the error, the callback will not be called at
Michael> all, since deferred processing will look for the second callback
Michael> at that point by the diagram.

Michael> So, right now I'm calling my own callback from the errback if I
Michael> want to swallow the error. Is there a better way?

Yes. Add the errback to the deferred and then add the callback.

  d = somethingReturningADeferred()

If cleanup doesn't return the failure object it's passed or raise some an
exception, processing will pass to dealWithResult. Note that dealWithResult
will get as an argument whatever cleanup returns (that means None if cleanup
doesn't explicitly return something).

You're thinking about this in the right way. Understanding the difference
between the above and 

  d = somethingReturningADeferred()
  d.addCallbacks(dealWithResult, cleanup)

is important.


More information about the Twisted-Python mailing list