Le 29/03/2012 20:28, Claudiu Saftoiu a écrit :
I have an HTTP request which has roughly two parts to it. One part
requires a lot of processing with a small chance of a DatabaseConflict,
while the other part requires little processing with a high chance of
a DatabaseConflict. I'd like to do something like this:
for avar in something:
My question is: how will automatic retrying work? Most of my views are
and, if something conflicts, the whole thing is just retried. In
what will happen if the `slow_no_conflict()` function has a conflict?
What will happen if the `fast_yes_conflict(avar)` function has a conflict?
What if its in the first iteration of the loop, or the last? I'm not
how to properly think about these things yet.
Hello retry shall be made on a transaction basis.
I would say, that while for the regular_view retry may be handled by a
middleware or such (the publisher in Zope2 ?), you may want to manage it
in my_view around your transaction.
in my_view you do transaction commit, so you won't undo the
slow_no_conflict part if you fail in the second part (if it was not your
intent you shall use subtransactions).
So you may do something like :
from ZODB.POSException import ConflictError
do_retry = True
do_retry = False
except Exception, e:
do_retry = isinstance(e, ConflictError)
Hope this helps !
06 78 33 15 37
For more information about ZODB, see http://zodb.org/
ZODB-Dev mailing list - ZODB-Dev@zope.org