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

Method acquire_context

xarray/backends/file_manager.py:205–213  ·  view source on GitHub ↗

Context manager for acquiring a file.

(self, needs_lock: bool = True)

Source from the content-addressed store, hash-verified

203
204 @contextmanager
205 def acquire_context(self, needs_lock: bool = True) -> Iterator[T_File]:
206 """Context manager for acquiring a file."""
207 file, cached = self._acquire_with_cache_info(needs_lock)
208 try:
209 yield file
210 except Exception:
211 if not cached:
212 self.close(needs_lock)
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."""

Callers 1

Calls 2

closeMethod · 0.95

Tested by 1