Re: modify cycles
"Eric S. Johansson" <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
Roger Binns wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Eric S. Johansson wrote:
>> yup. makes sense. I wonder why someone didn't make a method
>> implementing a transaction bounded method? haven't tested this yet but
>> it seems ok. feel free to use it if it helps anyone.
>
> Note that you need to put exception handling in your method so that
> rollback is called on errors and the isolation level restored.
what kind of exceptions? any I can retry or are they all the hard
failure type? without really knowing the exceptions and the proper
placement for begin/end/rollback, I'm guessing the form would look
something like the following. may need to add time delays when retrying
and retry counts:
def transaction(connection, fcn, args**):
success = False
old_isolation = connection.isolation_level
connection.isolation_level=None
c=connection.cursor()
c.execute("BEGIN")
while(True):
try:
fcn(c,args)
c.execute("END")
connection.commit()
success = True
break
except (..retryable exceptions...), error:
continue
except (..stbu exceptions...), error:
c.execute("ROLLBACK")
break
connection.isolation_level = old_isolation
return success
--
Speech-recognition in use. It makes mistakes, I correct some.