Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory mapping on Windows #193

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions sheeprl/utils/memmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import numpy as np
from numpy.typing import DTypeLike

from sheeprl.utils.imports import _IS_WINDOWS


def is_shared(array: np.ndarray) -> bool:
return isinstance(array, np.ndarray) and hasattr(array, "_mmap")
Expand Down Expand Up @@ -214,12 +212,12 @@ def from_array(

def __del__(self) -> None:
"""Delete the memory-mapped array. If the memory-mapped array has ownership of the file and no other
reference to the memory-mapped array exists or the OS is Windows-based,
reference to the memory-mapped array exists,
then the memory-mapped array will be flushed to disk and both the memory-mapped array and
the file will be closed. If the memory-mapped array is mapped to a temporary file then the file is
removed.
"""
if (self._has_ownership and getrefcount(self._file) <= 2) or _IS_WINDOWS:
if self._array is not None and self._has_ownership and getrefcount(self._file) <= 2:
self._array.flush()
self._array._mmap.close()
del self._array._mmap
Expand Down