Hello

I'm writing client code that uses ZODB over a ZEO connection. In order not to have to call connection.sync() to synchronise the cache with the server I wish to provide the ZEO client with an asyncore mainloop to which it can attach itself. No matter how I do this, however, my clients do not seem to be processing cache invalidation/update messages asynchronously.

My client code does not make use of asyncore itself so the thread is started especially for ZEO's use. I've tried starting the loop thread *after* getting the ZEO connection:

==============================
class AsyncoreRunner(threading.Thread):
    def __init__(self,env):
        threading.Thread.__init__(self)
        self.env=env
        self.setDaemon(True)

    def run(self):
        self.env.sys.logger.info("Asyncore loop starting")
        try:
            asyncore.loop()
        except Exception,ex:
            self.env.sys.logger.error("Asyncore loop quitting: %s"%str(ex))
        self.env.sys.logger.info("Asycore loop ended")



addr = host, port
storage=ClientStorage.ClientStorage(addr)
db = DB(self.storage)
conn = self.db.open()
mt = AsyncoreRunner(self.env)
mt.start()
==============================

... and I've tried starting it BEFORE getting the connection (providing a dummy dispatcher so that the asyncore.loop() does not return immediately).

In either case, if I run two clients the following does not work where I would imagine it should if the messages were being processed on the asyncore thread.

CLIENT 1:
root = conn.root()
root['test']=10
transaction.commit()

CLIENT 2:
root['test']
... KeyError...
conn.sync()
root['test']
10
root['test'] = 20
transaction.commit()

CLIENT1:
root['test']
10            <----- Not 20!
conn.sync()
root['test']
20            <----- now it is!


Have I misunderstood things very badly? Am I approaching things too simplistically?

I have googled and searched a lot of documentation but I just can't find the key to my problem! Here's hoping that someone on this list can help!

Many thanks in advance,
Matthew

_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to