[Twisted-Python] getProcessOutput ok to use in a DeferredList?

Andrew Bennetts andrew-twisted at puzzling.org
Mon May 26 03:28:23 EDT 2003

On Mon, May 26, 2003 at 04:50:58PM +1000, Stuart Hungerford wrote:

> I'd like to make use of the very neat DeferredList and also the
> utility function getProcessOutput(). My understanding is that
> getProcessOutput() returns a Deferred that returns a string of
> the process output.

Your understanding is correct.

> Are there any issues with passing a list of getProcessOutput()
> results to a DeferredList?  I understand the DeferredList still
> needs its own callback registered for completion of the list of
> deferreds.

There's nothing special going on.  As far as a DeferredList is concerned,
all Deferreds are the same.  Where the Deferred comes from is irrelevant.

> My initial tests with this setup just seem to suspend and not
> return, which is almost certainly something I've misunderstood
> in using Deferreds.

I suspect you're right, you probably are misunderstanding something.  It's
hard to say what, though, without more information.  (But when something is
mysteriously freezing, it's hard to know what information to give!)

A DeferredList, by default, calls its callbacks *only when all of its
Deferreds have fired*.  (If some of the Deferreds fail, that's ok, just so
long as they all call their callback/errback at some point).  A DeferredList
has no way of reporting partial results.

I'm going to guess what your problem might be, based on a problem I once
had.  :)

If you have multiple Deferreds, some "depend" on others, DeferredList's
default behaviour isn't what you want.  By "depend" I mean if Deferred A
fails (and so fires its errback, not callback), then Deferred B will never
be called, i.e. B depends on A.  (This is not official terminology! :).

In that case, you probably want to use the fireOnOneErrback flag of
DeferredList.  This changes the behaviour of DeferredList so that it will
fire its callbacks as soon as either:
    - All its Deferreds have fired their callbacks, or
    - any of its Deferreds have fired an errback.

Does any of this help you?


More information about the Twisted-Python mailing list