def put(self, key, value, overwrite=True): if self._invalid: raise lmdb.Error() assert self._write if not overwrite and key in self._storage: return False self._storage[key] = value return True
def delete(self, key): if self._invalid: raise lmdb.Error() assert self._write if key in self._storage: del self._storage[key] return True else: return False
def _open_env(path, write=False): path.mkdir(parents=True, exist_ok=True) t = 0 while t < 100: try: env = lmdb.open(path.as_posix(), create=True, max_dbs=1, max_readers=1024, lock=write, sync=True, map_size=10_737_418_240) return env except lmdb.Error as e: if 'No such file or directory' in e.args[0]: time.sleep(0.01) t += 1 else: raise e raise lmdb.Error( f"No such file or directory: {path}, with {t} times retry")
def commit(self): if self._invalid: raise lmdb.Error() self._invalidate() self._env._storage = self._storage
def get(self, key, default=None): if self._invalid: raise lmdb.Error() return self._storage.get(key, default)
def __enter__(self): if self._invalid: raise lmdb.Error() return self
def exists(self): if not os.path.isdir(self.p): raise lmdb.Error("LMDB not found (%s)")