Skip to content

Commit f4e0523

Browse files
keewisdcherian
andauthored
don't use CacheFileManager.__del__ on interpreter shutdown (#7880)
* store a reference to the acquire function on the object This keeps the function from being garbage collected before we can call it. * whats-new.rst * make `lock_acquire` a static method * fix rst link * comment on the existence of the static method `lock_acquire` * also store a reference to `OPTIONS` * revert storing additional references * remove `CachingFileManager.__del__` on interpreter shutdown * rephrase the changelog [skip-ci] * [skip-ci] --------- Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
1 parent c668582 commit f4e0523

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ Performance
4242

4343
Bug fixes
4444
~~~~~~~~~
45-
45+
- Don't call ``CachingFileManager.__del__`` on interpreter shutdown (:issue:`7814`, :pull:`7880`).
46+
By `Justus Magin <https://github.com/keewis>`_.
4647

4748
Documentation
4849
~~~~~~~~~~~~~

xarray/backends/file_manager.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import atexit
34
import contextlib
45
import io
56
import threading
@@ -289,6 +290,13 @@ def __repr__(self) -> str:
289290
)
290291

291292

293+
@atexit.register
294+
def _remove_del_method():
295+
# We don't need to close unclosed files at program exit, and may not be able
296+
# to, because Python is cleaning up imports / globals.
297+
del CachingFileManager.__del__
298+
299+
292300
class _RefCounter:
293301
"""Class for keeping track of reference counts."""
294302

0 commit comments

Comments
 (0)