Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions src/zarr/storage/_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ def __init__(
self._zmode = mode
self.compression = compression
self.allowZip64 = allowZip64
self._lock = threading.RLock()

def _sync_open(self) -> None:
if self._is_open:
raise ValueError("store is already open")

self._lock = threading.RLock()

self._zf = zipfile.ZipFile(
self.path,
mode=self._zmode,
Expand Down
12 changes: 12 additions & 0 deletions tests/test_store/test_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,15 @@ async def test_move(self, tmp_path: Path) -> None:
assert destination.exists()
assert not origin.exists()
assert np.array_equal(array[...], np.arange(10))

def test_lock_initialized_before_open(self, store_kwargs: dict[str, Any]) -> None:
"""Regression test for https://github.com/zarr-developers/zarr-python/issues/3588.

ZipStore._lock must be available immediately after __init__, before _open() is called,
so that operations like get/set/exists can use it even on non-opened stores.
"""
import threading

store = self.store_cls(**store_kwargs)
assert hasattr(store, "_lock"), "ZipStore._lock must be initialized in __init__"
assert isinstance(store._lock, type(threading.RLock())), "_lock must be an RLock"
Loading