Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
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")
Exemplo n.º 4
0
 def commit(self):
     if self._invalid:
         raise lmdb.Error()
     self._invalidate()
     self._env._storage = self._storage
Exemplo n.º 5
0
 def get(self, key, default=None):
     if self._invalid:
         raise lmdb.Error()
     return self._storage.get(key, default)
Exemplo n.º 6
0
 def __enter__(self):
     if self._invalid:
         raise lmdb.Error()
     return self
Exemplo n.º 7
0
 def exists(self):
     if not os.path.isdir(self.p):
         raise lmdb.Error("LMDB not found (%s)")