That way works, but the original problem was that a failure in one of them was stopping the whole callback chain. <br><br>Missing from my example (but present in a past example) was a try/except around the yield keyword. So:<br>
<br>...<br>try:<br> yield deferred1<br>except:<br> pass<br>...<br>try:<br> yield deferred2<br>except:<br> pass<br><br><br>would swallow any exceptions thrown by deferred1 and continue on to create deferred2. If you did:<br>
<br>d.addCallback(foo)<br>d.addCallback(bar)<br>d.addCallback(baz)<br><br>then an exception in "foo" would break the whole callback chain.<br><br><br> - Matt<br><br><div class="gmail_quote">On Thu, Sep 17, 2009 at 3:32 AM, Amaury Forgeot d'Arc <span dir="ltr"><<a href="mailto:amauryfa@gmail.com">amauryfa@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello,<br>
<br>
2009/9/17 Matt Perry <<a href="mailto:matt@unshift.net">matt@unshift.net</a>>:<br>
<div class="im">> Make sure you're using the @inlineCallbacks decorator and the yield<br>
> statement referenced previously. Without those you're just adding several<br>
> callbacks to the same Deferred; with them, the function will wait until the<br>
> Deferred fires before continuing.<br>
><br>
> def logRequest(self, *arg, **kw):<br>
> obj = copy.deepcopy(kw['obj'])<br>
><br>
> d = self.db.runInteraction(obj.first)<br>
><br>
> d.addCallback(self.db.runInteraction, obj.second, param1, param2)<br>
> d.addErrback(log.err)<br>
><br>
> d.addCallback(self.db.runInteraction, obj.third)<br>
> d.addErrback(log.err)<br>
<br>
</div>I don't understand your explanation. When a callback returns a Deferred itself,<br>
the main Deferred object waits for its completion before continuing.<br>
This is IMO the best feature of Deferreds!<br>
<br>
I often write code like the function above, so I would like to understand why<br>
it does not work in this case.<br>
<br>
--<br>
<font color="#888888">Amaury Forgeot d'Arc<br>
</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></div></blockquote></div><br>