[Twisted-Python] deferred proposed update

Fabrice Coudert fabrice.coudert at free.fr
Thu Jan 29 00:41:59 MST 2004


Tommi Virtanen a écrit :

> Fabrice Coudert wrote:
>
>> I 'd like to add a pre-processing and post-processing callback in a 
>> deferred callback list. I did somthing like this :
>
> >
> > my_defer = getADeferredForSomething()
> > new_defer = defer.Deferred()
> > new_defer.addCallback(preprocessing)
> > new_defer.chainDeferred(my_defer)
> > new_defer.addCallback(postprocessing)
> > my_defer = new_defer
>
> You are using Deferreds incorrectly. For example, nothing here
> makes new_defer ever trigger.

It is a sample code to show inconcistency of chainDeferred, not a real
case. Add my_defer.callback(True) after the sample code if you'd like
and trace it. You should see that postprocessing() is called with None
argument, but not with the result of previous callback as it should be
with a normal behaviour of deferred callbacks (read the tutorial)

>
> You haven't stated clearly what you want to do, but I don't see
> why you aren't just doing this:
>
> d = getADeferredForSomething()
> d.addCallback(preprocessing)
> d.addCallback(theRealMcCoy)
> d.addCallback(postprocessing)
>
Same as before, it is a *sample code*.
In real case theRealMcCoy (and some more methodes) is added before I
need to add a post/preprocessing to that defer.

So, I restate the probleme with chainDeferred :
chainDeferred(d) is equivalent to addCallbacks(d.callback, d.errback),
but this two methods are not really sort of callback methods for
deferred coz they didn't return a result.

effcy.











More information about the Twisted-Python mailing list