-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Don't close GzipFile before it is used #3893
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
Conversation
fo = gzip.GzipFile(None, 'wb', fileobj=fo) | ||
finally: | ||
if close: | ||
fo.close() | ||
surface = cairo.SVGSurface (fo, width_in_points, height_in_points) |
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.
while you are tinkering around in here, could you fix this extraneous space?
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.
eh, on second thought, I am seeing a bunch of them in this file... maybe it needs a separate PEP8 PR
In general, I think this is fine. It would be nice to have some sort of with-clause use, but I don't see that being easy to do at the moment. I am just utterly flummox in how this code even worked in the past. |
BUG : Don't close GzipFile before it is used
Looking at the gzip docs, https://docs.python.org/2/library/gzip.html#gzip.GzipFile, it looks like the I think we are still leaking a file handle, but that should be dealt with separately. |
BUG : Don't close GzipFile before it is used
cherry-picked as c02a515 |
Fixes issue #1883 for me on Windows.
Consider the code at https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_cairo.py#L478:
In case the GzipFile is created from the open file created with
fo = open(fo, 'wb')
:The proposed changes should close all GzipFile and open file instances when/if necessary.