Skip to content

Commit

Permalink
Ensure that the reader object is freed before returning
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 29, 2024
1 parent 137e131 commit 7b92707
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions python/lsst/obs/base/formatters/fitsExposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,15 @@ def read_from_local_file(self, path: str, component: str | None = None, expected
# With FormatterV2 that file descriptor does not refer to a local
# file.
self._reader_path = path
self._reader = None # Reset any cache.
if component is not None:
return self.readComponent(component)
return self.readFull()
self._reader = None # Ensure the reader class is reset.
try:
if component is not None:
in_memory_dataset = self.readComponent(component)
else:
in_memory_dataset = self.readFull()
finally:
self._reader = None # Release the file handle.
return in_memory_dataset

@abstractmethod
def readComponent(self, component):
Expand Down

0 comments on commit 7b92707

Please sign in to comment.