Explicitly close any associated file object (if necessary).
(self, needs_lock: bool = True)
| 232 | return file, True |
| 233 | |
| 234 | def close(self, needs_lock: bool = True) -> None: |
| 235 | """Explicitly close any associated file object (if necessary).""" |
| 236 | # TODO: remove needs_lock if/when we have a reentrant lock in |
| 237 | # dask.distributed: https://github.com/dask/dask/issues/3832 |
| 238 | with self._optional_lock(needs_lock): |
| 239 | default = None |
| 240 | file = self._cache.pop(self._key, default) |
| 241 | if file is not None: |
| 242 | file.close() |
| 243 | |
| 244 | def __del__(self) -> None: |
| 245 | # If we're the only CachingFileManger referencing an unclosed file, |