[ZODB-Dev] Automating retry management

2010-05-11 Thread Jim Fulton
So I'm about to update the transaction package and this gives me an opportunity to do something I've been meaning to do for a while, which is to add support for the Python with statement: with transaction: ... transaction body ... and: with some_transaction_manager as t:

Re: [ZODB-Dev] Automating retry management

2010-05-11 Thread Nitro
I'm already using custom transaction/savepoint context managers in my code. I use them like with TransactionContext(): db.root['sp_test'] = 'init' with SavepointContext(): db.root['sp_test'] = 'saved' On of the context managers: class TransactionContext(object): def

Re: [ZODB-Dev] Automating retry management

2010-05-11 Thread Nitro
def __exit__(self, t, v, tb): if t is not None: self.txn.abort() else: for i in range(self.retryCount): Oops, bug here. It should read range(1 + self.retryCount). It should probably have unittests anyway :-) -Matthias

Re: [ZODB-Dev] Automating retry management

2010-05-11 Thread Benji York
On Tue, May 11, 2010 at 7:34 AM, Jim Fulton j...@zope.com wrote: [...] The best I've been able to come up with is something like:    t = ZODB.transaction(3)    while t.trying:        with t:            ... transaction body ... I think you could get this to work: for transaction in

Re: [ZODB-Dev] Automating retry management

2010-05-11 Thread Jim Fulton
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 =

Re: [ZODB-Dev] Automating retry management

2010-05-11 Thread Jim Fulton
On Tue, May 11, 2010 at 8:38 AM, Benji York be...@zope.com wrote: On Tue, May 11, 2010 at 7:34 AM, Jim Fulton j...@zope.com wrote: [...] The best I've been able to come up with is something like:    t = ZODB.transaction(3)    while t.trying:        with t:            ... transaction body

Re: [ZODB-Dev] Automating retry management

2010-05-11 Thread Benji York
On Tue, May 11, 2010 at 10:08 AM, Jim Fulton j...@zope.com wrote: This is an improvement. It's still unsatisfying, but I don't think I'm going to get satisfaction. :) Given that PEP 343 explicitly mentions *not* supporting an auto retry construct, I should think not. :) -- Benji York

Re: [ZODB-Dev] Automating retry management

2010-05-11 Thread Nitro
Am 11.05.2010, 16:01 Uhr, schrieb Jim Fulton j...@zope.com: 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

Re: [ZODB-Dev] Automating retry management

2010-05-11 Thread Nitro
Am 11.05.2010, 17:08 Uhr, schrieb Nitro ni...@dr-code.org: Am 11.05.2010, 16:01 Uhr, schrieb Jim Fulton j...@zope.com: 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

Re: [ZODB-Dev] Automating retry management

2010-05-11 Thread Laurence Rowe
On 11 May 2010 15:08, Jim Fulton j...@zope.com wrote: On Tue, May 11, 2010 at 8:38 AM, Benji York be...@zope.com wrote: On Tue, May 11, 2010 at 7:34 AM, Jim Fulton j...@zope.com wrote: [...] The best I've been able to come up with is something like:    t = ZODB.transaction(3)    while