[Twisted-Python] understanding deferreds
Hello, I've been reading up on this http://twistedmatrix.com/documents/current/core/howto/defer.html I'm a bit confused as to the "visual explanation". It seems like if you have a single callback and errback, that if the errback wants to swallow the error, the callback will not be called at all, since deferred processing will look for the second callback at that point by the diagram. So, right now I'm calling my own callback from the errback if I want to swallow the error. Is there a better way? Thanks, Mike -- Michael P. Soulier <msoulier@digitaltorque.ca> "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction." --Albert Einstein
On 10:28 pm, msoulier@digitaltorque.ca wrote:
Hello,
I've been reading up on this
http://twistedmatrix.com/documents/current/core/howto/defer.html
I'm a bit confused as to the "visual explanation". It seems like if you have a single callback and errback, that if the errback wants to swallow the error, the callback will not be called at all, since deferred processing will look for the second callback at that point by the diagram.
There are at least three ways you can have a single callback and errback: d.addCallback(cb) d.addErrback(eb) or d.addErrback(eb) d.addCallback(cb) or d.addCallbacks(cb, eb) All three of these do something different.
So, right now I'm calling my own callback from the errback if I want to swallow the error. Is there a better way?
It sounds like you want the middle option above. Jean-Paul
On Fri, Jan 29, 2010 at 12:39 AM, <exarkun@twistedmatrix.com> wrote:
There are at least three ways you can have a single callback and errback:
d.addCallback(cb) d.addErrback(eb)
or
d.addErrback(eb) d.addCallback(cb)
Just to expand on exarkun's answer a little, it might help to understand that addCallback and addErrback are simply implemented in terms of addCallbacks. Roughly: def passthru(arg): return arg d.addCallback(cb) is equivalent to d.addCallbacks(cb, passthru) d.addErrback(eb) is equivalent to d.addCallbacks(passthru, eb) -- mithrandi, i Ainil en-Balandor, a faer Ambar
On 29/01/10 Tristan Seligmann said:
Just to expand on exarkun's answer a little, it might help to understand that addCallback and addErrback are simply implemented in terms of addCallbacks. Roughly:
def passthru(arg): return arg
d.addCallback(cb) is equivalent to d.addCallbacks(cb, passthru)
d.addErrback(eb) is equivalent to d.addCallbacks(passthru, eb)
I think I understand now. I don't think it's adequately explained here http://twistedmatrix.com/documents/current/core/howto/defer.html but the diagram makes more sense now. Thanks, Mike -- Michael P. Soulier <msoulier@digitaltorque.ca> "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction." --Albert Einstein
participants (3)
-
exarkun@twistedmatrix.com
-
Michael P. Soulier
-
Tristan Seligmann