Skip to content

Commit

Permalink
Add a weakref finalizer to FitsProxy instances (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjperkins authored Mar 18, 2024
1 parent e23eab6 commit e528649
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ History

X.Y.Z (YYYY-MM-DD)
------------------
* Add a weakref.finalize method to close HDUList objects on FitsProxy instances (:pr:`12`)
* Depend on fsspec (:pr:`11`)
* Improve dask array name determinism (:pr:`10`)
* Change license from GPL3 to BSD3 (:pr:`9``)
Expand Down
5 changes: 3 additions & 2 deletions xarrayfits/fits_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def hdu_list(self):
try:
return self._hdul
except AttributeError:
self._hdul = fits.open(self._filename, **self._kwargs)
return self._hdul
self._hdul = hdul = fits.open(self._filename, **self._kwargs)
weakref.finalize(self, hdul.close)
return hdul

def __hash__(self):
return hash((self._filename, tuple(set(self._kwargs.items()))))
Expand Down

0 comments on commit e528649

Please sign in to comment.