MCPcopy Index your code
hub / github.com/pydata/xarray / _acquire_with_cache_info

Method _acquire_with_cache_info

xarray/backends/file_manager.py:215–232  ·  view source on GitHub ↗

Acquire a file, returning the file and whether it was cached.

(self, needs_lock: bool = True)

Source from the content-addressed store, hash-verified

213 raise
214
215 def _acquire_with_cache_info(self, needs_lock: bool = True) -> tuple[T_File, bool]:
216 """Acquire a file, returning the file and whether it was cached."""
217 with self._optional_lock(needs_lock):
218 try:
219 file = self._cache[self._key]
220 except KeyError:
221 kwargs = self._kwargs
222 if self._mode is not _OMIT_MODE:
223 kwargs = kwargs.copy()
224 kwargs["mode"] = self._mode
225 file = self._opener(*self._args, **kwargs)
226 if self._mode == "w":
227 # ensure file doesn't get overridden when opened again
228 self._mode = "a"
229 self._cache[self._key] = file
230 return file, False
231 else:
232 return file, True
233
234 def close(self, needs_lock: bool = True) -> None:
235 """Explicitly close any associated file object (if necessary)."""

Callers 2

acquireMethod · 0.95
acquire_contextMethod · 0.95

Calls 2

_optional_lockMethod · 0.95
copyMethod · 0.45

Tested by

no test coverage detected