from . import lib
from bsddb3 import db as bd
+__all__ = ["environment", "database"]
+
deadlock = bd.DBLockDeadlockError
class environment(lib.closable):
def __init__(self, env, flags=bd.DB_TXN_WRITE_NOSYNC):
self.tx = env.txn_begin(None, flags)
self.done = False
+ self.pcommit = set()
def commit(self):
self.done = True
self.tx.commit(0)
+ def run1(list):
+ if len(list) > 0:
+ try:
+ list[0]()
+ finally:
+ run1(list[1:])
+ run1(list(self.pcommit))
def abort(self):
self.done = True
self.abort()
return False
+ def postcommit(self, fun):
+ self.pcommit.add(fun)
+
+def dloopfun(fun):
+ def wrapper(self, *args, **kwargs):
+ while True:
+ try:
+ return fun(self, *args, **kwargs)
+ except deadlock:
+ continue
+ return wrapper
+
def txnfun(envfun):
def fxf(fun):
def wrapper(self, *args, tx=None, **kwargs):