from .db import txnfun
class environment(object):
- def __init__(self, path):
- self.path = path
+ def __init__(self, *, path=None, getpath=None, recover=False):
+ if path is not None:
+ self.path = path
+ self.getpath = None
+ else:
+ self.path = None
+ self.getpath = getpath
+ self.recover = recover
self.lk = threading.Lock()
self.bk = None
def __call__(self):
with self.lk:
if self.bk is None:
- self.bk = db.environment(self.path)
+ if self.path is None:
+ self.path = self.getpath()
+ self.bk = db.environment(self.path, recover=self.recover)
return self.bk
def close(self):
if env:
self.env = env
else:
- self.env = environment(path)
+ self.env = environment(path=path)
self._db = None
if ncache is None:
ncache = cache.cache()