[ZODB-Dev] newbie ZEO first try. ConflictError.
Christian Theune
ct at gocept.com
Fri Nov 27 00:53:29 EST 2009
Hi,
On 11/26/2009 10:55 PM, tsmiller wrote:
>
> Christian,
> Thanks. How painfully obvious. I have written the words
> 'transaction.begin()' about a thousand times or so! But I get
> discombobulated when I start looking at something new ( ZEO ) and forget the
> obvious. Final code for this little test that works perfectly:
>
> while True:
> transaction.begin()
> root[ "one" ] = "program 2 - " + time.asctime()
> while True:
> try:
> transaction.commit()
> except POSException.ConflictError:
> time.sleep(.2)
> else:
> break
>
> time.sleep(5)
Two notes:
First, I'd leave the transaction.abort() right before the time.sleep().
Just to be explicit.
Second, the second while loop is superfluous - it doesn't do what it
looks like and what you might think it does. ;)
You can try committing exactly once. If you commit after a conflict
error, that will give you a different exception.
On the framework level conflict errors are usually handled by re-trying
the *whole* transaction once more. E.g. in Zope it means:
- abort the transaction
- start a new transaction
- process the request as it was again
If it fails for three times then Zope gives up and hands the conflict
error to the user.
Christian
--
Christian Theune · ct at gocept.com
gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 0 · fax +49 345 1229889 1
Zope and Plone consulting and development
More information about the ZODB-Dev
mailing list