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

Add option to close all mmaps when calling HDUList.close() #3962

Closed
embray opened this issue Jul 14, 2015 · 1 comment
Closed

Add option to close all mmaps when calling HDUList.close() #3962

embray opened this issue Jul 14, 2015 · 1 comment

Comments

@embray
Copy link
Member

embray commented Jul 14, 2015

Over in #3827 the point was raised that it would be useful to have an option, when closing a FITS file, to make sure all handles to that file, including handles used by mmap'd data arrays are closed. This could be an optional argument to HDUList.close() and / or an argument to fits.open (and hence HDUList.fromfile) that ensures this cleanup is performed when the file is closed.

This might also be a decent opportunity to revisit what the default behavior should be. I'm on the fence.

It's worth adding that if my plans for a FITSData container object ever come to fruition, this could be handled more transparently at a lower level. The FITSData could handle opening and closing mmaps on an as-needed basis, so that merely accessing hdu.data (which would return a FITSData or some higher-level wrapper around that) does not cause any side-effects like opening file handles.

@embray
Copy link
Member Author

embray commented Aug 27, 2015

As discussed in #4097, it turns out that HDUList.close() already closes any mmaps in use, and they'll only hang around if there are any external references to an array with a mmap buffer. However, since we don't know how those external references will be used, we need to leave the mmap open (otherwise Numpy segfaults, though even if that weren't the case it would result in surprising behavior to the user when they suddenly can't read their array anymore). So as written this isn't really a good idea.

The possibility for a FITSData container to improve this situation still stands, and is something I will keep in mind for the future.

@embray embray closed this as completed Aug 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant