[Twisted-Python] Making DeferredList look like Deferred

Lenny G Arbage alengarbage at yahoo.com
Fri Feb 3 15:18:56 EST 2006

I have a need to return a DeferredList or a Deferred
from a function, but I don't want the caller to be
aware of this distinction -- the caller should just
assume that they got a regular Deferred.

The way I'm currently accomplishing this is to 1)
ensure that each Deferred in the List has its own
callback/errback pair hooked up, and 2) add a callback
to the Deferred list from within the called function
which either returns the [possibly sanitized] result
if all the Deferreds called their callbacks, or that
raises a failure.DefaultException if any of the
Deferreds called their errbacks.  This seems to give
me the desired result in all cases.

Is this the right way to go about this?  Is there a
cleaner way?

(The reason I can't just return the DeferredList, as I
understand, is that its callback is *always* invoked,
even if we leave each of the Deferred's errbacks
unhooked and let them trickle up into DeferredList's
addErrback callable.  In the case of a caller who
expects the returned deferred to be a regular
deferred, it would not be expected to have *both* its
callback and errback invoked).


Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

More information about the Twisted-Python mailing list