You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix possible dataloss during finalization with GzipFile #159422
After stumbling into #159419, which addresses possible dataloss during finalization. I decided to take a quick pass across some of our other writers to see if the same bug exists elsewhere. I came across this issue in GzipFile, where trying to import a module at finalization could trigger an ImportError that results in the file never being properly closed.
current implementation
def__del__(self):
ifself.mode==WRITEandnotself.closed:
importwarnings# If warnings fails to loadwarnings.warn("unclosed GzipFile",
ResourceWarning, source=self, stacklevel=2)
super().__del__() # then, this line will never run
example
importgzipf=gzip.open("out.gz", "wb")
f.write(b"important data\n"*1000)
# never explicitly closed; finalized at shutdown
$ python repro.py
Exception ignored while calling deallocator <function GzipFile.__del__ ...>:
ImportError: sys.meta_path is None, Python is likely shutting down
Activity