Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #9287: Resource leak of file handles
Open resources (ordinary file, HDF5, tar, urlopen response, etc.) were often not closed properly. When an exception is raised the resource might not be closed. This may eg. result in depleting the number of file handles for the process.
Where possible use context managers (
with open(...) as f
) that close the resource even after catching an exception.Still,
HDF5Matrix
,CSVLogger
andkeras.preprocess.image.load_img()
are difficult to fix without changing their API. In those places resource ownership is not properly defined. See comment for HDF5Matrix.PIL images returned by
load_img()
should be closed by the user of that function. Possibly using it's context manager:However, I'm not 100% sure if this can be disturbed by operations such as
img.convert()
,img.resize()
done inload_img()
.