[Twisted-Python] PBClientFactory and getRootObject

Jean-Paul Calderone exarkun at divmod.com
Fri Apr 10 10:09:41 MDT 2009


On Thu, 2 Apr 2009 23:31:12 +0200, Fabrizio Mancini <mr.file at gmail.com> wrote:
>Hi everyone,
>I'm writing a server and a client using Perspective Broker with no Avatar
>and no auth.
>The server accumulates some data using a DeferredQueue.
>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.
>What i want to know is:
>1) how can i recursively call the remote method to retrieve the items from
>the server?
>2) can i defer the database operations to a thread so every client can
>elaborates multiple requests per time?

I don't really understand either of these questions.

> [snip code]
>
>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.
>Is this correct?
>Do I have to always call self.clientfactory.getRootObject() every time i
>have to call a remote method?

You don't.  You only need to call it once per connection, to get the root
object.  Once you have the root object, you can simply keep a reference to
it and use it to make any number of remote calls you like.

>Can i deferToThread the function got_item or
>self.dbpool.runOperation(query)?

runOperation implies threading already, since DB-API 2.0 is blocking.  So
you should already have all the threading you need.

Jean-Paul




More information about the Twisted-Python mailing list