Oh I like the look of the inlineCallbacks. Is there a way that I can still use inspect.getargspec to retrieve the arg names of my original method, as opposed to the generator returned by inlineCallbacks.<div><br></div><div>
I noticed it copies the __doc__ over, but is there an attribute where I can still inspect my original method?<br><br><div class="gmail_quote">On Tue, Nov 17, 2009 at 11:08 AM, Reza Lotun <span dir="ltr">&lt;<a href="mailto:rlotun@gmail.com">rlotun@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi Landreville,<br>
<div class="im"><br>
&gt; If I want to do a number of actions in a row that each return a deferred but<br>
&gt; depend on eachother, do I need to nest those callbacks?<br>
&gt; Ie if i want to:<br>
&gt; 1. Call database function using adbabi<br>
&gt; 2. Call xmlrpc method using result from 1<br>
&gt; 3. Call database using result from 2<br>
&gt; Would I just put 2 inside the callback for 1 and then put 3 inside the<br>
&gt; callback for 2?<br>
<br>
</div>By multiple deferreds that depend on each other, you probably mean a<br>
linear firing of actions based on callbacks of previous actions. The<br>
only way to do that is to trigger actions in callbacks of the<br>
deferreds in question, as you allude to.<br>
<br>
Yeah, so roughly something like this would work:<br>
<br>
def db_call(arg):<br>
   dfr = make_db_call_in_thread(arg)<br>
   return dfr<br>
<br>
def xmlrpc_call(arg):<br>
   dfr = make_call(arg)<br>
   return dfr<br>
<br>
dfr = db_call(some_initial_arg)<br>
dfr.addCallback(xmlrpc)<br>
dfr.addCallback(db_call)<br>
<div class="im"><br>
&gt; How would I do that in one function? All the examples I have seen have a<br>
&gt; function calling one method returning a deferred and then placing the logic<br>
&gt; (doing something with the result) in the callback, but do not deal with<br>
&gt; multiple deferreds that depend on each other.<br>
<br>
</div>To do it in one function, you could use something like:<br>
<br>
def complex_call():<br>
    def db_call(arg):<br>
       dfr = make_db_call_in_thread(arg)<br>
       return dfr<br>
<br>
    def xmlrpc_call(arg):<br>
       dfr = make_call(arg)<br>
       return dfr<br>
<br>
    dfr = db_call(some_initial_arg)<br>
    dfr.addCallback(xmlrpc_call)<br>
    dfr.addCallback(db_call)<br>
    dfr.addErrback(my_errback_handler)<br>
    return dfr<br>
<br>
Or you can make each handler a method on a class. Another way to do it<br>
is to use inlineCallbacks:<br>
<br>
from twisted.internet import defer<br>
@defer.inlineCallbacks<br>
def example():<br>
    res = yield db_call(some_initial_arg)<br>
    rpc_res = yield xmlrpc_call(res)<br>
    db_res = yield db_call(rpc_res)<br>
<br>
In the above example, it&#39;s all still asynchronous (if not parallel),<br>
but it looks like it&#39;s synchronous, using the magic of decorators and<br>
Python 2.5+&#39;s ability to retrieve results from yield statements.<br>
<br>
Hope that makes sense.<br>
<br>
Cheers,<br>
Reza<br>
<font color="#888888"><br>
--<br>
Reza Lotun<br>
mobile: +44 (0)7521 310 763<br>
email:  <a href="mailto:rlotun@gmail.com">rlotun@gmail.com</a><br>
work:   <a href="mailto:reza@tweetdeck.com">reza@tweetdeck.com</a><br>
twitter: @rlotun<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></div>