[Twisted-Python] deferred proposed update
exarkun at intarweb.us
Thu Jan 29 23:48:18 EST 2004
On Wed, Jan 28, 2004 at 07:22:40PM +0100, Fabrice Coudert wrote:
> 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)
Without a use case, there's no chance of the behavior changing. False
consistency is the hobgoblin of, etc.
> >You haven't stated clearly what you want to do, but I don't see
> >why you aren't just doing this:
> >d = getADeferredForSomething()
> 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.
If the code you included in your message isn't equivalent to the code
you're using in your actual application, then it's a waste of time to
discuss it. If it is equivalent, I don't see why you can't use the code
> 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.
If it doesn't do what you want, don't use it. For that matter, even if it
does, you can probably avoid using it. As glyph stated, it is a hold-over
from times past. If you can share the real use case, maybe someone can help
you reformulate it in terms of more recent APIs.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: Digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20040129/a45c4a07/attachment.pgp
More information about the Twisted-Python