Skip to content

Commit 6e83d44

Browse files
authored
prevent another ResourceWarning in GzipFile due to an unclosed myfileobj
1 parent 6dab428 commit 6e83d44

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Lib/gzip.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ def __init__(self, filename=None, mode=None,
250250
self._write_gzip_header(compresslevel)
251251
except BaseException:
252252
# Avoid a ResourceWarning if the write fails, eg read-only file or KI
253+
try:
254+
if self.myfileobj is not None:
255+
self.myfileobj.close()
256+
finally:
257+
self.fileobj = None
253258
self.fileobj = None
254259
raise
255260

0 commit comments

Comments
 (0)