On Tue, May 11, 2010 at 7:52 AM, Nitro <ni...@dr-code.org> wrote:
> I'm already using custom transaction/savepoint context managers in my
> code. I use them like

...
> Now you could probably extend this to look like
>
> class TransactionContext(object):
>     def __init__(self, txn = None, retryCount = 3):
>         if txn is None:
>             txn = transaction.get()
>         self.txn = txn
>         self.retryCount = retryCount
>
>     def __enter__(self):
>         return self.txn
>
>     def __exit__(self, t, v, tb):
>         if t is not None:
>             self.txn.abort()
>         else:
>             for i in range(self.retryCount):
>                 try:
>                     self.txn.commit()
>                 except ConflictError as exc2:
>                     exc = exc2
>                 else:
>                     return
>             raise exc
>
> The looping/except part could probably look nicer. Use case looks like:
>
> with TransactionContext(mytransaction, retryCount = 5):
>     db.root['sp_test'] = 'init'
>
> Does this look similar to what you were looking for?

This wouldn't work.  You would need to re-execute the suite
for each retry. It's not enough to just keep committing the same
transaction. (There are other details wrong with the code above,
but they are fixable.)  Python doesn't provide a way to keep
executing the suite.

Jim

-- 
Jim Fulton
_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
https://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to