[Twisted-Python] addCallbacks issue

Tim Allen screwtape at froup.com
Tue Apr 13 06:41:13 MDT 2004


On 13 Apr 2004, at 20:31, Andrew Bennetts wrote:
> On Tue, Apr 13, 2004 at 01:19:30AM -0700, Sorin C. wrote:
>> 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?
>
> You misunderstand the documentation, which is a shame because that 
> section
> is there specifically to be as clear as possible about this point :(  I
> wonder how we can do better?

I think part of the problem is that people speak of "the callback 
chain", when there's actually two mutually intertwined callback chains.

It's been a while since I read the Twisted docs, but maybe they should 
explicitly mention that in the context of addCallbacks(), the callback 
is called to turn a successful operation into a successful upstream 
result, and the errback is called to turn an unsuccessful operation 
into a successful upstream result. The upstream errback only gets 
called if the current situation is utterly unsalvageable.

Another way of approaching the concept might be to say that each stage 
in the chain has to deal with the errors in the chain before it - that 
is, if you do:

	d.addCallbacks(cb, eb)

then eb needs to handle any errors that arise from the data source, 
while if you do:

	d.addCallback(cb)
	d.addErrback(eb)

then eb needs to handle any errors that arise from the data source, AND 
any errors that arise from cb.





More information about the Twisted-Python mailing list