[Twisted-Python] Callbacks, Looping, and Variable Binding
justinjohnson at fastmail.fm
Fri Aug 1 07:57:36 EDT 2003
> Yes. I'd make that prettier with
> def onSuccess(results, item):
> d = item.doSomethingElseThatReturnsDeferred()
> return d
> for item in list:
> d.addCallback(onSuccess, item)
Yes, that looks much cleaner.
> > > Besides, you are adding the outer d to deferreds once per
> > > iteration. That's broken.
> > I'm not sure what you mean here. I was adding my deferred to a list and
> > it seemed to be doing what I wanted (at least I think it was).
> Your original code had
> > d = doSomethingThatReturnsDeferred()
> > for item in list:
> > d.addCallbacks(onSuccess, log.err)
> > deferreds.append(d)
> Which ends up adding the _same_ d len(list) times to deferreds.
Ahhh.... I see. That was a result of me rewriting my code for the post
to this list, and not putting things in their original place. Thanks for
More information about the Twisted-Python