[ZODB-Dev] ZEO client with Asyncore loop
Matthew Pontefract
matthew-p at moving-picture.com
Thu Dec 7 12:44:23 EST 2006
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
More information about the ZODB-Dev
mailing list