The attached code is designed to output compressed data to a gzip file. It creates two GzipFile objects, but only one is really used. It seems that it doesn't clean up and close the file properly. In Py2, the attached code will fail. The output file (debug.txt.gz) will be corrupt. However if the self.unused line is commented out, it works and the file is not corrupted. In Py3, a sys.exit call at the end is required to see the same behaviour. As example output, when the sys.exit is include in Py3, the output is below and the file is corrupt. Compressor.__init__ UnusedClass.write UnusedClass.write UnusedClass.write UnusedClass.write UnusedClass.write UnusedClass.write Compressor.compressToFile And when the sys.exit is commented out, the console output is below and the file is not corrupt. Compressor.__init__ UnusedClass.write UnusedClass.write UnusedClass.write UnusedClass.write UnusedClass.write UnusedClass.write Compressor.compressToFile UnusedClass.write UnusedClass.write UnusedClass.write
The documentation states that: Calling a GzipFile object’s close() method does not close fileobj, since you might wish to append more material after the compressed data. This also allows you to pass an io.BytesIO object opened for writing as fileobj, and retrieve the resulting memory buffer using the io.BytesIO object’s getvalue() method. (https://docs.python.org/3.8/library/gzip.html) It's reasonable that, since you opened the file, you would also be responsible for closing it.
As for the bug you report - I was unable to reproduce it on windows (python 3.10) or linux (python 3.7). Can you check again to see if you still observe it, and give info on the system and python version if so?
History
Date
User
Action
Args
2022-04-11 14:58:53
admin
set
github: 75867
2020-10-20 10:02:11
iritkatriel
set
status: open -> closedresolution: works for mestage: resolved