Mailing List Archive

gzip bug?
gzip file objects don't seem to close themselves automatically. When I
do this:
cPickle.dump(object,gzip.open('file','w'))

Only a couple hundred bytes are written. However everything works find
when I do this:
f=gzip.open('file','w')
cPickle.dump(object,f)
f.close()

Cheers,
Chris


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
gzip bug? [ In reply to ]
On Mon, 09 Aug 1999 21:55:46 GMT,
catlee@my-deja.com <catlee@my-deja.com> wrote:
>gzip file objects don't seem to close themselves automatically. When I
>do this:

Because they don't have a __del__ method, so when you're writing the
output file isn't closed (and the checksum isn't written). Try this
patch:

Index: gzip.py
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Lib/gzip.py,v
retrieving revision 1.12
diff -C3 -r1.12 gzip.py
*** gzip.py 1999/04/12 14:34:16 1.12
--- gzip.py 1999/08/10 01:16:51
***************
*** 251,256 ****
--- 251,259 ----
self.myfileobj.close()
self.myfileobj = None

+ def __del__(self):
+ if self.myfileobj is not None: self.close()
+
def flush(self):
self.fileobj.flush()


--
A.M. Kuchling http://starship.python.net/crew/amk/
The quality of what is said inevitably influences the way in which it is said,
however inexperienced the writer.
-- Robertson Davies, _A Voice from the Attic_