This adds the __enter__ and __exit__ methods to the MultiTransact class in client.py, so that MultiTransact instances can be used with the with construct. The __exit__ method, which is used to clean-up resources, is presently implemented by trying to abort the transaction. I am presuming that if the transaction has already been committed, then attempting to abort with raise a runtime error and will not change any state in the db. I'd consider a solution in which I was able to check the state of the transaction from python to be more elegant, but I didn't see such an API available. For another PR, perhaps.
This also updates the README to document the usage of multi-transactions as a context-manager.
This adds the
__enter__
and__exit__
methods to theMultiTransact
class inclient.py
, so thatMultiTransact
instances can be used with thewith
construct. The__exit__
method, which is used to clean-up resources, is presently implemented by trying to abort the transaction. I am presuming that if the transaction has already been committed, then attempting to abort with raise a runtime error and will not change any state in the db. I'd consider a solution in which I was able to check the state of the transaction from python to be more elegant, but I didn't see such an API available. For another PR, perhaps.This also updates the README to document the usage of multi-transactions as a context-manager.