[ZODB-Dev] Mutlithreaded ZODB applications.
Dieter Maurer
dieter at handshake.de
Thu Jan 17 18:18:17 EST 2008
Kenneth Miller wrote at 2008-1-17 15:03 -0600:
>I see in the user guide that it mentions that you need to have a connection
>instance per thread to allow multiple threads to access a particular FS.
>Does anyone have any simple example code on doing this?
News threads usually have a form like:
import transaction
from ZODB.POSException import ConflictError
conn = db.open() # open a new ZODB connection
root = conn.root()
try:
retry = True
while retry:
retry = False
try:
do_your_function(root)
transaction.commit()
except ConflictError:
transaction.abort()
retry = True # you may want to restrict the possible retry number
except:
transaction.abort()
# you may want to log your exception in some way
raise
finally:
conn.close()
--
Dieter
More information about the ZODB-Dev
mailing list