Skip to content

Removing Python 3 ResourceWarning: unclosed file warnings may need AstroPy change  #365

Closed

Description

@DougBurke

I've been looking into whether we can remove the ResourceWarning filters we have in sherpa/conftest.py that were added in the Python 3 conversion. Some of these are being created by AstroPy and bubble up into Sherpa (due to the "interesting" way we deal with file I/O and throw a kitchen-sink of read routines at a file until one sticks). Here's an example of the issue, using AstroPy 1.3.3 and Python 3.5:

% cat dummy.dat 
# A B
0.5 1.65
% 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))
% 

Running this script produces the warning:

% 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>

Activity

  1. DougBurke commented on Jun 8, 2017

    @DougBurke
    ContributorAuthor
  2. DougBurke commented on Aug 30, 2017

    @DougBurke
    ContributorAuthor

    With astropy 2.0.1 (on Python 3.6) I no-longer get a warning:

    % python dummy.py 
    --> Header missing END card.
    
  3. DougBurke commented on May 18, 2018

    @DougBurke
    ContributorAuthor

    I think this can be closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions