Fix: close image files after use during palette check #68
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.
With pypy, nmlc trivially trips file handle limits on macOS during palette checks, resulting in: "[Errno 24] Too many open files".
This is a common enough problem in python, which can be resolved by either
ulimit -n 4096
on a per shell basisImage.close()
, whereImage.open()
has been usedThis PR closes images opened for palette checks, which is a trivial case. Errno 24 no longer triggers for me. Tests pass.
Errno 24 does not trigger for me with any cPython 3.x, but pypy cuts run times by up to 50% in my testing compared to cPython 3.8, so we do want to be compatible with pypy.
There are a couple of other uses of Image.open() but they looked less trivial, and they're not tripping Errno 24 for me.
For the record,
Image.load()
self-closes so wouldn't have the same issue, butImage.open()
is often the wanted command, especially for reading metadata.