Hi everyone,<br>I&#39;m writing a server and a client using Perspective Broker with no Avatar and no auth.<br>The server accumulates some data using a DeferredQueue.<br>The clients using a remote call retrieve one item per time from the queue and elaborates it making some changes on a database using adbapi.<br>
What i want to know is: <br>1) how can i recursively call the remote method to retrieve the items from the server?<br>2) can i defer the database operations to a thread so every client can elaborates multiple requests per time?<br>
<br>The code i&#39;m using is this:<br><br>from twisted.internet import reactor, defer, pb<br>from twisted.enterprise import adbapi<br>from twisted.python import log<br>import os<br><br>globalConfigurationFile=os.path.abspath(&#39;conf&#39; + os.sep + &#39;configuration.ini&#39;)<br>
<br>class DataBasePreparerClient(object):<br>    &#39;&#39;&#39;<br>    DataBasePreparerClient()<br>    &#39;&#39;&#39;<br>    <br>    def __init__(self, globalConfigurationFile):<br>        self._gcf = globalConfigurationFile<br>
        self.data = {}<br>        self._parseConfig()<br>
        self._createDbPool()<br>        self.d = defer.Deferred()<br>        self.clientfactory = pb.PBClientFactory()<br>        <br>    def _createDbPool(self):<br>        self.dbpool = adbapi.ConnectionPool(&#39;cx_Oracle&#39;, self.data[&#39;db_username&#39;], self.data[&#39;db_password&#39;], self.data[&#39;db_tns&#39;])<br>
    <br>    def connect(self):<br>        reactor.connectTCP(self.data[&#39;server_ip&#39;], self.data[&#39;server_port&#39;], self.clientfactory)<br>        self.d = self.clientfactory.getRootObject()<br>        self.dbpool.connect()<br>
        self.d.addCallbacks(self.get_item, self._eb)<br><br>    def _eb(self, reason):<br>
        print &quot;Failure: &quot;, reason.getErrorMessage()<br>
    <br>
    def get_item(self, result):<br>
        d = result.callRemote(&quot;get_item&quot;)<br>
        d.addCallback(self.got_item)<br>
        <br>    def got_item(self, item):<br>        query = &quot;update table where ...&quot;<br>        res = self.dbpool.runOperation(query)<br>        res.addErrback(self._eb)<br>        self.d = self.clientfactory.getRootObject()<br>
        self.d.addCallbacks(self.get_item, self._eb)<br>    <br>if __name__ == &quot;__main__&quot;:<br>    DataBasePreparerClient(globalConfigurationFile).connect()<br>    reactor.run()<br><br>To call recursively the remote object in function connect i call clientfactory.getRootObject() and addCallback() for the first time, and the i recall always self.clientfactory.getRootObject() and self.d.addCallback when the db query has completed.<br>
Is this correct?<br>Do I have to always call self.clientfactory.getRootObject() every time i have to call a remote method?<br>Can i deferToThread the function got_item or self.dbpool.runOperation(query)?<br>Thanks in advance<br>
Fabrizio<br>