Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure when closing, to explicitly close data blocks #533

Merged
merged 3 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- Update asdf-standard to reflect more stringent (and, consequently, more
correct) requirements on the formatting of complex numbers. [#526]

- Fix bug with dangling file handle when using ASDF-in-FITS. [#533]

2.0.2 (2018-07-27)
------------------

Expand Down
2 changes: 1 addition & 1 deletion asdf/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ def close(self):
self._data.flush()
if self._data._mmap is not None:
self._data._mmap.close()
self._data = None
self._data = None


class UnloadedBlock(object):
Expand Down
34 changes: 34 additions & 0 deletions asdf/tests/test_fits_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,37 @@ def test_verify_with_astropy(tmpdir):

with fits.open(tmpfile) as hdu:
hdu.verify('exception')

def test_dangling_file_handle(tmpdir):
"""
This tests the bug fix introduced in #533. Without the bug fix, this test
will fail when running the test suite with pytest-openfiles.
"""
import gc

fits_filename = str(tmpdir.join('dangling.fits'))

# Create FITS file to use for test
hdulist = fits.HDUList()
hdulist.append(fits.ImageHDU(np.arange(512, dtype=np.float)))
hdulist.append(fits.ImageHDU(np.arange(512, dtype=np.float)))
hdulist.append(fits.ImageHDU(np.arange(512, dtype=np.float)))
hdulist.writeto(fits_filename)
hdulist.close()

hdul = fits.open(fits_filename)
gc.collect()

ctx = asdf.AsdfFile()
gc.collect()

ctx.blocks.find_or_create_block_for_array(hdul[0].data, ctx)
gc.collect()

hdul.close()
gc.collect()

ctx.close()
gc.collect()

del ctx