-
Notifications
You must be signed in to change notification settings - Fork 442
Conversation
Thanks for your quick followup @rragundez! I had thought the same, but it seems closing the filehandler before returning the object forbids a number of operations on the returned object. Minimal example:
That will throw For what it's worth, the approach here is straight from the Pillow docs on file handling. That said, I'm happy to make any changes you see fit! |
Thanks for your explanations. After having a closer look I think the root of the problem is the inconsistency The drawback is of course that for no augmentation the image object occupies more memory but since this function is used in the Iterator class in a loop where it gets immediately converted to an array then is OK. I would do the change above and simply add a unit-test that |
@rragundez Your approach ( How does the updated PR look? |
@rragundez ah I was testing against a cached version of the module--it appears the load method is missing from PIL.Image--where did you see that method? |
It appears it acts over the https://pillow.readthedocs.io/en/3.1.x/reference/Image.html?highlight=load#PIL.Image.Image.load then something like |
Hmm, these two return different objects:
I understand the Pillow docs on the That said, combining open and load don't seem to close the file handlers. Returning PixelAccess data rather than a PIL Image object also breaks some methods in
It's entirely possible I misunderstood you or am missing something! From my perspective, using the io stream method outlined in the Pillow docs seems the best way forward... |
@rragundez sounds good! I just submitted some updates with the changes you requested. The flake8 checks are of course going to fail because of the undefined |
I think is good now, I'll have a closer look tomorrow :) |
thanks for your help with this! |
No problem, I don't understand why I still see changes in |
thanks for the work @duhaime! |
Summary
The current
load_img
function opens files but never closes them, which can causeOSError: [Errno 24] Too many open files
if one reads in too many images in a process.Related Issues
#260
PR Overview