Make sure you&#39;re using the @inlineCallbacks decorator and the yield statement referenced previously.  Without those you&#39;re just adding several callbacks to the same Deferred; with them, the function will wait until the Deferred fires before continuing.<br>
<br>def logRequest(self, *arg, **kw):<br>
    obj = copy.deepcopy(kw[&#39;obj&#39;])<br>
<br>
    d = self.db.runInteraction(obj.first)<br><div id=":1s0" class="ii gt">
<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><br>Note that &quot;d&quot; is the same Deferred throughout.  If you change it to:<br><br>@inlineCallbacks<br>def logRequest(self, *arg, **kw):<br>
    obj = copy.deepcopy(kw[&#39;obj&#39;])<br>
<br>
    firstDeferred = self.db.runInteraction(obj.first)<br><div id=":1s0" class="ii gt">  
yield firstDeferred<br><br>  # code here won&#39;t get resumed until &quot;firstDeferred&quot; has a result<br>  print firstDeferred.result<br>    <br>  secondDeferred = self.db.runInteraction(obj.second)<br>  yield secondDeferred<br>
<br>  # same as above, code won&#39;t get executed until &quot;secondDeferred&quot; has a result<br><br>then you&#39;ll get the behavior you&#39;re looking for.<br><br>See <a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.defer.html#inlineCallbacks">http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.defer.html#inlineCallbacks</a> for some more information.<br>
<br>   - Matt<br></div><br></div><br><br><div class="gmail_quote">On Wed, Sep 16, 2009 at 12:18 PM, Pet <span dir="ltr">&lt;<a href="mailto:petshmidt@googlemail.com">petshmidt@googlemail.com</a>&gt;</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;">
<div><div></div><div class="h5">On Tue, Sep 15, 2009 at 6:21 PM, Pet &lt;<a href="mailto:petshmidt@googlemail.com">petshmidt@googlemail.com</a>&gt; wrote:<br>
&gt; On Tue, Sep 15, 2009 at 5:19 PM, Mark Visser &lt;<a href="mailto:markv@lumierevfx.com">markv@lumierevfx.com</a>&gt; wrote:<br>
&gt;&gt; <a href="mailto:exarkun@twistedmatrix.com">exarkun@twistedmatrix.com</a> wrote:<br>
&gt;&gt;&gt; On 10:37 am, <a href="mailto:petshmidt@googlemail.com">petshmidt@googlemail.com</a> wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I&#39;d like to run several queries in background, some of them may fail.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; If you have a function along the lines of this one:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     def someInteractions(db):<br>
&gt;&gt;&gt;         interactions = [<br>
&gt;&gt;&gt;             db.runInteraction(one),<br>
&gt;&gt;&gt;             db.runInteraction(two),<br>
&gt;&gt;&gt;             db.runInteraction(three)]<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Then a failure in one shouldn&#39;t affect two or three; likewise for any<br>
&gt;&gt;&gt; other failure or combination of failures.  They are naturally (ugh, not<br>
&gt;&gt;&gt; a good word, but I can&#39;t think of a better one) independent.  You have<br>
&gt;&gt;&gt; to go out of your way to associate them somehow.<br>
&gt;&gt;&gt;<br>
&gt;&gt; I think he might mean he wants them to run sequentially, even if one fails.<br>
&gt;&gt;<br>
&gt;&gt; You can do that explicitly via @inlineCallbacks like this:<br>
&gt;&gt;<br>
&gt;&gt; @inlineCallbacks<br>
&gt;&gt; def someInteractions(db):<br>
&gt;&gt;    try:<br>
&gt;&gt;        yield db.runInteraction(one)<br>
&gt;&gt;    except:<br>
&gt;&gt;       pass<br>
&gt;&gt;<br>
&gt;&gt;    try:<br>
&gt;&gt;        yield db.runInteraction(two)<br>
&gt;&gt;    except:<br>
&gt;&gt;       pass<br>
&gt;&gt;<br>
&gt;&gt;    try:<br>
&gt;&gt;        yield db.runInteraction(three)<br>
&gt;&gt;    except:<br>
&gt;&gt;       pass<br>
&gt;&gt;<br>
&gt;&gt; Or with callback/errbacks, like this:<br>
&gt;&gt;<br>
&gt;&gt; def someInteractions(db)<br>
&gt;&gt;        d = db.runInteraction(one).addBoth(db.runInteraction,<br>
&gt;&gt; two).addBoth(db.runInteraction, three)<br>
&gt;<br>
<br>
</div></div>Hi,<br>
<br>
<br>
I&#39;ve tried to do following:<br>
<br>
def logRequest(self, *arg, **kw):<br>
    obj = copy.deepcopy(kw[&#39;obj&#39;])<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>
<br>
unfortunately it doesn&#39;t work in that way, because I suppose, obj is<br>
destroyed if second or third interaction starts.<br>
Is there a way to solve this?<br>
<br>
Thanks, Pet<br>
<div><div></div><div class="h5"><br>
&gt; Hi Mark!<br>
&gt;<br>
&gt; Yes, I&#39;d like run them sequentially, it was not clear for me, how to<br>
&gt; do it in one deferred.<br>
&gt;<br>
&gt; I will try your suggestions out.<br>
&gt;<br>
&gt; Thanks for help!<br>
&gt;<br>
&gt; Pet<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; addBoth is a convenience method that adds the same function as a<br>
&gt;&gt; callback and an errback:<br>
&gt;&gt;<br>
&gt;&gt; <a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.defer.Deferred.html#addBoth" target="_blank">http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.defer.Deferred.html#addBoth</a><br>

&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; Mark Visser, Software Director<br>
&gt;&gt; Lumière VFX<br>
&gt;&gt; Email: <a href="mailto:markv@lumierevfx.com">markv@lumierevfx.com</a><br>
&gt;&gt; Phone: +1-514-316-1080 x3030<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Twisted-Python mailing list<br>
&gt;&gt; <a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
&gt;&gt; <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
&gt;&gt;<br>
&gt;<br>
<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>