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

missing ad.close() or equivalent #424

Open
phirstgemini opened this issue Mar 1, 2023 · 1 comment
Open

missing ad.close() or equivalent #424

phirstgemini opened this issue Mar 1, 2023 · 1 comment

Comments

@phirstgemini
Copy link
Contributor

There doesn't appear to be any way to cause AstroData to close a file that was opened with astrodata.open(). It seems that in many cases the file ends up getting closed when the ad object goes out of scope or has zero refcount or something, but it also seems like we shouldn't be relying on this.

@jehturner
Copy link
Contributor

From @saimn:

Writing is not an issue, the code uses HDUList.write :

hdul.writeto(filename, overwrite=overwrite)

Reading is more complicated. the file is kept opened and IIRC it's mostly because the hdu is wrapped with FitsLazyLoadable to delay the scaling:
parts[part_name] = FitsLazyLoadable(parts[part_name])

And on top of that, when using memmap, each .data array also needs a file handle to load the data when needed.

So I guess adding a .close() method would be a good idea, but currently the ad object doesn't keep a reference to the HDUList to close it. I'm not completely sure what would happen when accessing ad.data after the fie is closed though, it may depend on whether ad.data had been used or not (astropy will closes the memmap handles if there are not references to hdu.data, and since there is FitsLazyLoadable in between, I'm not sure. Also accessing a closed memmap object will segfault, so needs to be checked).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants