[ZODB-Dev] transaction "Attempts" class
Zvezdan Petkovic
zvezdan at computer.org
Wed Mar 28 18:11:19 UTC 2012
On Mar 28, 2012, at 2:47 AM, Chris McDonough wrote:
> Not sure what you'd say there.. "a for loop has to be broken out of for the for loop to not loop"? ;-)
I believe Thierry is talking about the issue I filed long time ago.
https://bugs.launchpad.net/transaction/+bug/724332
The way this feature is described in the docs, one expects that:
- it tries to commit up to N times in presence of conflict errors, but
- it leaves the loop after the first successful commit.
(otherwise, if it succeeds in the attempt K, it commits N-K times)
Currently, one has to write the code in this manner:
for tx_attempt in transaction.attempts(5):
with tx_attempt as tx:
# Do some work that tries to commit here
# Workaround for unexpected behavior of `attempts` generator
# in transaction-1.1.1 so we can break out after commit.
if tx.status == 'Committed':
break
I'm really not sure that checking tx.status is the *best* way to go, but it's one way that works.
Best regards,
Zvezdan
More information about the ZODB-Dev
mailing list