I am trying to understand this concept of async methods and i thought I had it cracked with the code below but it doesn&#39;t seem to work as all the calls to the xmlrpc server return one after the other like this:<br><br>
Success:I started at Fri Apr 24 01:12:23 2009 and i slept 5 seconds then woke at Fri Apr 24 01:12:28 2009<br>Success:I started at Fri Apr 24 01:12:28 2009 and i slept 5 seconds then woke at Fri Apr 24 01:12:33 2009<br>Success:I started at Fri Apr 24 01:12:33 2009 and i slept 5 seconds then woke at Fri Apr 24 01:12:38 2009<br>
Success:I started at Fri Apr 24 01:12:38 2009 and i slept 5 seconds then woke at Fri Apr 24 01:12:43 2009<br>Success:I started at Fri Apr 24 01:12:43 2009 and i slept 5 seconds then woke at Fri Apr 24 01:12:48 2009<br>Success:I started at Fri Apr 24 01:12:48 2009 and i slept 5 seconds then woke at Fri Apr 24 01:12:53 2009<br>
<br>Am I completly missing the point here or is there something incorrect with my code. AT first I thought it was because the sleep was shutting the whole thing down (probably is) so  I have also tried it with a long running network call instead of the time.sleep() and have the same issue. Can someone please point me in the right direction or give a bit of criticism of the code concepts/thought processes<br>
<br><br>=========== Server ========================<br>#!/usr/bin/env python<br><br>from twisted.web import xmlrpc, server<br>from twisted.internet.defer import Deferred<br>from twisted.internet import reactor, threads<br>
import time<br><br>class MyServer(xmlrpc.XMLRPC):<br><br>    def blocking_method(self, duration=5):<br>        &quot;&quot;&quot;block the instance for a specified duration&quot;&quot;&quot;<br>        started = time.asctime()<br>
        time.sleep(duration)<br>        data = &quot;I started at %s and i slept %d seconds then woke at %s&quot; % (started, duration, time.asctime())<br>        return data<br><br><br>#    def xmlrpc_block_thread(self, duration=10):<br>
#        &quot;&quot;&quot; pass to blocking method using thread &quot;&quot;&quot;<br>#        return threads.deferToThread(self.blocking_method, duration)<br>#<br>#    def xmlrpc_block(self, duration=10):<br>#        &quot;&quot;&quot; pass to blocking method using defered &quot;&quot;&quot;<br>
#        d = Deferred()<br>#        d.callback(self.blocking_method(duration))<br>#        return d<br><br>    def xmlrpc_block_fixed(self, duration=5):<br>        &quot;&quot;&quot; pass to blocking method using defered &quot;&quot;&quot;<br>
        d = self.blocking_method_fixed(duration)  # return a defered<br>        d.addCallback(self.printdata)<br>        d.addErrback(self.printerror)<br>        return d<br><br>    def blocking_method_fixed(self, duration=5):<br>
        d = Deferred()<br>        d.callback(self.blocking_method(duration))<br>        return d<br><br>    def printdata(self, val):<br>        return &#39;Success:&#39;+val<br><br>    def printerror(self, val):<br>        return &#39;Error:&#39;+val<br>
<br><br>if __name__ == &#39;__main__&#39;:<br>    r = MyServer()<br>    reactor.listenTCP(8080, server.Site(r))<br>    reactor.run()<br><br>===============================================<br><br><br>========== Client ================================<br>
#!/usr/bin/env python<br>import xmlrpclib<br>import datetime<br>import sys<br>proxy = xmlrpclib.ServerProxy(&quot;<a href="http://localhost:8080/">http://localhost:8080/</a>&quot;, allow_none=True)<br>print &quot;%s&quot; % str(proxy.block_fixed(5))<br>
<br>===============================================<br><br><br><br><br clear="all">Tim Hughes<br>mailto:<a href="mailto:thughes@thegoldfish.org">thughes@thegoldfish.org</a><br><br><br>