Skip to content

ResourceWarning from astropy.io.fits.open when input isn't a valid FITS file #6168

@DougBurke

Description

@DougBurke

With astropy 1.3.3 and python 3.5 (and apparently also the current master branch), the following code

% cat dummy.py
import warnings
from astropy.io import fits

warnings.simplefilter(action='error', category=ResourceWarning)

try:
    fits.open('dummy.dat')
except OSError as e:
    print("--> {}".format(e))

produces this output (the problem is the ResourceWarning that is being raised):

% python dummy.py 
--> Header missing END card.
Exception ignored in: <_io.FileIO name='dummy.dat' mode='rb' closefd=True>
ResourceWarning: unclosed file <_io.FileIO name='dummy.dat' mode='rb' closefd=True>

for an invalid FITS file, such as

% cat dummy.dat
# A B
0.5 1.65

There has been some discussion of this at #6082 (comment) but it seems worth a separate issue.

Note that this may seem an odd thing to do - i.e. use a FITS open command on a non-FITS file - but it would be useful to https://github.com/sherpa/sherpa to handle this without the warning (since we do some odd things in the name of not breaking user expectations). At present we have to skip these warnings in our tests and it would be preferable to have warning-free code as much as possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions