New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force closing PIL image files #972
Conversation
@@ -1185,12 +1185,20 @@ def imread(fname, format=None): | |||
can be used with :func:`~matplotlib.pyplot.imshow`. | |||
""" | |||
|
|||
def pilread(): | |||
def pilread(fname): | |||
"""try to load the image with PIL or return None""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you have extended the capability of this function (file handles are now supported), can you improve the doctoring a little. Perhaps the variable name fname
is no longer appropriate - maybe something like img_file
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the capability of the function is the same as before. It just works around another bug in PIL, which does not seem to close all the files it opens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. but the variable naming statement still holds (fname
could be a file handle or a filename).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it is a good idea to rename the variable. fname
is used as an argument in the outer function. Renaming it there would break the API. Renaming it in pilread
only would be confusing I think.
+1 |
Looks good. |
what is holding up this PR? |
Nothing. |
This fixes some
ResourceWarning: unclosed file
warnings under Python 3.2