Opened 8 years ago

Closed 7 years ago

#950 closed defect (fixed)

Most of the readers don't close files properly.

Reported by: andyfaff Owned by: krzywon
Priority: major Milestone: SasView 4.2.0
Component: SasView Keywords:
Cc: Work Package: SasView Bug Fixing

Description

Whilst inspecting the file reading code in sas.sascalc.dataloader.readers I discovered that most of the file readers don't close the file once they've finished with them.

The files should be opened with a context manager:

with open(filename, 'r') as f:

# do stuff

A lot of this abstraction could occur in a superclass that all the Readers could inherit. The specific readers being given an open file handle, which the superclass would close. Alternatively it could be done with a decorator.

Relevant files are: abs_reader, anton_paar_saxs_reader, ascii_reader (uses close but it'd be easier with a context manager), cansas_reader, danse_reader, hfir1d_reader, tiff_reader.

Change History (2)

comment:1 Changed 8 years ago by krzywon

  • Owner set to krzywon
  • Status changed from new to accepted

I'm already working on a refactor of the data loader system and had the same idea of abstracting the readers. I'll take this.

comment:2 Changed 7 years ago by GitHub <noreply@…>

  • Resolution set to fixed
  • Status changed from accepted to closed

In f001bc9e4b9d1ac0d4712117442f0c949334dbc4/sasview:

Merge pull request #95 from lewisodriscoll/ticket-876

Refactor File Loaders - fixes #889 #950 #849 #876 #922 #983 #970

Note: See TracTickets for help on using tickets.