[Twisted-Python] addCallbacks issue

Sorin C. soso_pub at yahoo.com
Tue Apr 13 04:19:30 EDT 2004


Hi,

Yes, I saw this bit of documentation but what I
understand from it is that if you chain multiple
addCallbacks to the same deferred then the error
handler from the last addCallbacks call will be
called. What am I missing?
Anyway, the API docs say:

"""
addCallbacks(self, callback, errback=None,
callbackArgs=None, callbackKeywords=None,
errbackArgs=None, errbackKeywords=None, asDefaults=0)

Add a pair of callbacks (success and error) to this
Deferred.
"""

So shouldn't 

addCallbacks(success, failure)

be equivalent with

addCallback(success)
addErrback(failure)

?
--- Christopher Armstrong <radix at twistedmatrix.com>
wrote:
> Sorin C. wrote:
> > Any idea why addCallbacks fails to bound the error
> > handler? I use Twisted 1.2.0.
> 
> Read the documentation.
> 
> http://twistedmatrix.com/documents/howto/defer
> 
> """
> There's another potential gotcha here. There's a
> method 
> twisted.internet.defer.Deferred.addCallbacks which
> is similar to, but 
> not exactly the same as, addCallback followed by
> addErrback. In 
> particular, consider these two cases:
> 
> # Case 1
> d = getDeferredFromSomewhere()
> d.addCallback(callback1)
> d.addErrback(errback1)
> d.addCallback(callback2)
> d.addErrback(errback2)
> 
> # Case 2
> d = getDeferredFromSomewhere()
> d.addCallbacks(callback1, errback1)
> d.addCallbacks(callback2, errback2)
> 
> If an error occurs in callback1, then for Case 1
> errback1 will be called 
> with the failure. For Case 2, errback2 will be
> called. Be careful with 
> your callbacks and errbacks.
> 
> """
> 
> -- 
>   Twisted | Christopher Armstrong: International Man
> of Twistery
>    Radix  |          Release Manager,  Twisted
> Project
> ---------+           http://radix.twistedmatrix.com/



	
		
__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/




More information about the Twisted-Python mailing list