Skip to content

Commit

Permalink
Fixed mmap-related errors on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
birchkwok committed Sep 15, 2024
1 parent dffbd7f commit 3f7dc12
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
3 changes: 1 addition & 2 deletions lynse/execution_layer/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ def build_binary():
f'{self.storage_worker.fingerprint}.*SQ8.index')
)

sq8_data = np.load(self.index_data_path / f'{self.storage_worker.fingerprint}.sqd',
mmap_mode='r')
sq8_data = np.load(self.index_data_path / f'{self.storage_worker.fingerprint}.sqd')

_index.data = binary_data
_index.ids = binary_ids
Expand Down
24 changes: 15 additions & 9 deletions lynse/storage_layer/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,22 @@ def return_if_in_memory(self, filename):

def load_data(self, filename, data_path, indices_path, update_memory=True, is_mmap=True):
with self.lock:
if not is_mmap:
with open(data_path / filename, 'rb') as f:
with open(data_path / filename, 'rb') as f:
data = np.load(f)
with open(indices_path / filename, 'rb') as f:
indices = np.load(f)
else:
with NpyLoader(data_path / filename) as _data:
data = np.asarray(_data)
with NpyLoader(indices_path / filename) as _indices:
indices = np.asarray(_indices)
with open(indices_path / filename, 'rb') as f:
indices = np.load(f)

# ignore mmap
# if not is_mmap:
# with open(data_path / filename, 'rb') as f:
# data = np.load(f)
# with open(indices_path / filename, 'rb') as f:
# indices = np.load(f)
# else:
# with NpyLoader(data_path / filename) as _data:
# data = np.asarray(_data)
# with NpyLoader(indices_path / filename) as _indices:
# indices = np.asarray(_indices)

if update_memory:
self.write_to_memory(filename, data, indices)
Expand Down
14 changes: 4 additions & 10 deletions lynse/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,23 @@ def wrapper(*args, **kwargs):


def load_chunk_file(filename):
np_array = np.load(filename)
np_array = np.load(filename, mmap_mode='r')
return np_array


class NpyLoader:
def __init__(self, filename):
self.filename = filename
self.np_array = None
# self.mmap = None

def __enter__(self):
self.np_array = load_chunk_file(self.filename)

# self.mmap = getattr(self.np_array, 'base', None)

return self.np_array

def __exit__(self, exc_type, exc_value, traceback):
pass
# if self.np_array is not None:
# del self.np_array
# if self.mmap is not None and hasattr(self.mmap, 'close'):
# self.mmap.close()
self.np_array._mmap.close()
self.np_array = None




Expand Down

0 comments on commit 3f7dc12

Please sign in to comment.