From f9925aec6b6057a377f712d21cb02292fd31f540 Mon Sep 17 00:00:00 2001 From: David Bold Date: Wed, 24 Sep 2025 20:00:17 +0200 Subject: [PATCH 1/2] Add assert to CombinedLock If you have a non-blocking acquire, you have to release all the locks that you did acquire, but you must not release any of the locks that have been locked by another thread. As it is not stored which locks where acquired, the release is not possible. It is thus not save to use this function without locking. --- xarray/backends/locks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xarray/backends/locks.py b/xarray/backends/locks.py index 784443544ee..60efe7632bd 100644 --- a/xarray/backends/locks.py +++ b/xarray/backends/locks.py @@ -218,6 +218,7 @@ def __init__(self, locks: Sequence[Lock]): self.locks = tuple(set(locks)) # remove duplicates def acquire(self, blocking=True): + assert blocking, "Without blocking you will never know which locks you have to unlock!" return all(acquire(lock, blocking=blocking) for lock in self.locks) def release(self): From f124da39fa8e1ea80f6610299a57caae12cce4c4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 Sep 2025 18:02:09 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/backends/locks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xarray/backends/locks.py b/xarray/backends/locks.py index 60efe7632bd..16331b9d1b1 100644 --- a/xarray/backends/locks.py +++ b/xarray/backends/locks.py @@ -218,7 +218,9 @@ def __init__(self, locks: Sequence[Lock]): self.locks = tuple(set(locks)) # remove duplicates def acquire(self, blocking=True): - assert blocking, "Without blocking you will never know which locks you have to unlock!" + assert blocking, ( + "Without blocking you will never know which locks you have to unlock!" + ) return all(acquire(lock, blocking=blocking) for lock in self.locks) def release(self):