[ZODB-Dev] Multithreaded FileStorage access example.

Kenneth Miller xkenneth at gmail.com
Thu Jan 17 16:18:32 EST 2008


Just figured it out, hope it's helpful to someone.
import threading
import time
from ZODB import DB,FileStorage
import transaction

class myThread(threading.Thread):
    def run(self):
        time.sleep(1)
        print "Access from thread"
        threadConn = db.open()
        threadRoot = threadConn.root()
        print "The root as opened by the thread:",threadRoot
        print "Main writing to the root"
        threadRoot['thread']=1
        print "Committing transcation"
        transaction.commit()

newThread = myThread()

storage = FileStorage.FileStorage('data.fs')
db = DB(storage)

newThread.start()
print "Access from main"
mainConn = db.open()

mainRoot = mainConn.root()
print "The root as opened by the main:",mainRoot
print "Main writing to the root"
mainRoot['main']=1
print "Committing transaction"
transaction.commit()


newThread.join()

Regards,
Kenneth Miller
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zodb-dev/attachments/20080117/84e0711d/attachment-0001.htm


More information about the ZODB-Dev mailing list