From fac27de9f57973f8571b3ec87ec3c74ee955d7ee Mon Sep 17 00:00:00 2001 From: Joris Snellenburg Date: Sun, 3 Oct 2021 14:15:08 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Use=20a=20context=20manager=20wh?= =?UTF-8?q?en=20opening=20a=20nc=20dataset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit avoid file locking when calling xarray.open_dataset --- glotaran/builtin/io/netCDF/netCDF.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/glotaran/builtin/io/netCDF/netCDF.py b/glotaran/builtin/io/netCDF/netCDF.py index 69f9b6b54..12fc47693 100644 --- a/glotaran/builtin/io/netCDF/netCDF.py +++ b/glotaran/builtin/io/netCDF/netCDF.py @@ -11,7 +11,8 @@ @register_data_io("nc") class NetCDFDataIo(DataIoInterface): def load_dataset(self, file_name: str) -> xr.Dataset | xr.DataArray: - return xr.open_dataset(file_name) + with xr.open_dataset(file_name) as ds: + return ds.load() def save_dataset( self,