Add patch and timeout to tests

This commit is contained in:
David Bold
2025-09-28 01:36:42 +02:00
parent 185ae2fc83
commit b402b2518a
2 changed files with 101 additions and 1 deletions
+93
View File
@@ -0,0 +1,93 @@
diff --git a/xarray/backends/file_manager.py b/xarray/backends/file_manager.py
index 2a6f3691..aa4bf14d 100644
--- a/xarray/backends/file_manager.py
+++ b/xarray/backends/file_manager.py
@@ -9,7 +9,7 @@ import warnings
from collections.abc import Hashable
from typing import Any
-from xarray.backends.locks import acquire
+from xarray.backends.locks import NETCDF4_PYTHON_LOCK, acquire
from xarray.backends.lru_cache import LRUCache
from xarray.core import utils
from xarray.core.options import OPTIONS
@@ -339,9 +339,16 @@ class _HashedSequence(list):
class DummyFileManager(FileManager):
"""FileManager that simply wraps an open file in the FileManager interface."""
- def __init__(self, value, *, close=None):
+ def __init__(
+ self,
+ value,
+ *,
+ close=None,
+ lock: Lock | None | Literal[False] = None,
+ ):
if close is None:
close = value.close
+ self._lock = lock
self._value = value
self._close = close
@@ -355,5 +362,8 @@ class DummyFileManager(FileManager):
yield self._value
def close(self, needs_lock=True):
- del needs_lock # ignored
- self._close()
+ if needs_lock and self._lock:
+ with self._lock:
+ self._close()
+ else:
+ self._close()
diff --git a/xarray/backends/locks.py b/xarray/backends/locks.py
index 82d3e0b7..a857d904 100644
--- a/xarray/backends/locks.py
+++ b/xarray/backends/locks.py
@@ -281,3 +281,6 @@ def ensure_lock(lock):
if lock is None or lock is False:
return DummyLock()
return lock
+
+
+NETCDF4_PYTHON_LOCK = combine_locks([NETCDFC_LOCK, HDF5_LOCK])
diff --git a/xarray/backends/netCDF4_.py b/xarray/backends/netCDF4_.py
index d6a37b06..3561966c 100644
--- a/xarray/backends/netCDF4_.py
+++ b/xarray/backends/netCDF4_.py
@@ -23,7 +23,7 @@ from xarray.backends.common import (
)
from xarray.backends.file_manager import CachingFileManager, DummyFileManager
from xarray.backends.locks import (
- HDF5_LOCK,
+ NETCDF4_PYTHON_LOCK,
NETCDFC_LOCK,
combine_locks,
ensure_lock,
@@ -58,8 +58,6 @@ if TYPE_CHECKING:
# string used by netCDF4.
_endian_lookup = {"=": "native", ">": "big", "<": "little", "|": "native"}
-NETCDF4_PYTHON_LOCK = combine_locks([NETCDFC_LOCK, HDF5_LOCK])
-
class BaseNetCDF4Array(BackendArray):
__slots__ = ("datastore", "dtype", "shape", "variable_name")
@@ -390,7 +388,7 @@ class NetCDF4DataStore(WritableCFDataStore):
"argument is provided"
)
root = manager
- manager = DummyFileManager(root)
+ manager = DummyFileManager(root, lock=NETCDF4_PYTHON_LOCK)
self._manager = manager
self._group = group
@@ -463,7 +461,7 @@ class NetCDF4DataStore(WritableCFDataStore):
if auto_complex is not None:
kwargs["auto_complex"] = auto_complex
manager = CachingFileManager(
- netCDF4.Dataset, filename, mode=mode, kwargs=kwargs
+ netCDF4.Dataset, filename, lock=lock, mode=mode, kwargs=kwargs
)
return cls(manager, group=group, mode=mode, lock=lock, autoclose=autoclose)
+8 -1
View File
@@ -11,6 +11,12 @@ Source: %pypi_source %{srcname}
# Fedora specific.
Patch: 0001-Drop-pydap-from-dependencies.patch
# RHBZ#2395128
# rebase of https://github.com/pydata/xarray/pull/10788.patch
# PR#10788 has merge conflicts
Patch: locking.patch
BuildArch: noarch
BuildRequires: python3-devel
@@ -20,6 +26,7 @@ BuildRequires: python3dist(dask[dataframe]) >= 2023.11
BuildRequires: python3dist(pint) >= 0.22
BuildRequires: python3dist(pytest) >= 2.7.1
BuildRequires: python3dist(pytest-xdist)
BuildRequires: python3dist(pytest-timeout)
BuildRequires: python3dist(rasterio) >= 1.3
BuildRequires: python3dist(seaborn) >= 0.13
@@ -72,7 +79,7 @@ pytest_args=(
-k 'not test_save_mfdataset_compute_false_roundtrip'
)
%{pytest} -ra "${pytest_args[@]}" --pyargs xarray
%{pytest} -ra "${pytest_args[@]}" --pyargs xarray --timeout 300 --full-trace
%files -n python3-%{srcname} -f %{pyproject_files}
%license licenses/*