From eca9b3be30f697c14e43e1ad717bf29ca13c6408 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Fri, 20 Mar 2015 06:14:59 +0100 Subject: [PATCH] Improved environment initialization. --- didex/store.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/didex/store.py b/didex/store.py index 15d2eca..450a9fe 100644 --- a/didex/store.py +++ b/didex/store.py @@ -3,15 +3,23 @@ from . import db, index, cache 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): @@ -41,7 +49,7 @@ class store(object): 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() -- 2.11.0