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

Method acquire

xarray/backends/file_manager.py:186–202  ·  view source on GitHub ↗

Acquire a file object from the manager. A new file is only opened if it has expired from the least-recently-used cache. This method uses a lock, which ensures that it is thread-safe. You can safely acquire a file in multiple threads at the same time, as long as

(self, needs_lock: bool = True)

Source from the content-addressed store, hash-verified

184 yield
185
186 def acquire(self, needs_lock: bool = True) -> T_File:
187 """Acquire a file object from the manager.
188
189 A new file is only opened if it has expired from the
190 least-recently-used cache.
191
192 This method uses a lock, which ensures that it is thread-safe. You can
193 safely acquire a file in multiple threads at the same time, as long as
194 the underlying file object is thread-safe.
195
196 Returns
197 -------
198 file-like
199 An open file object, as returned by ``opener(*args, **kwargs)``.
200 """
201 file, _ = self._acquire_with_cache_info(needs_lock)
202 return file
203
204 @contextmanager
205 def acquire_context(self, needs_lock: bool = True) -> Iterator[T_File]:

Calls 1