Need a little parse help
Fredrik Lundh
fredrik at pythonware.com
Wed May 11 14:21:37 EDT 2005
Peter Hansen wrote:
> > Remember, finalisers are not called when Python exits. So if you don't
> > explicitly close the file you are *writing* to, it may not be flushed
> > before being closed (by the OS because the process no longer exists).
>
> Ouch... I'd forgotten/never heard that I guess. If that's true and all
> there is to the matter, I would think we'd all have encountered numerous
> times when our output files were not properly written. Yet I've never
> encountered this situation myself, nor heard of anyone else ever having
> trouble as a result of it. What gives?
that's probably because finalizers *are* called when Python exits.
$ python2.4
>>> f = open("out", "w")
>>> f.write(100000*"x")
>>> import os
>>> os._exit(1)
$ ls -l out
-rw-rw-r-- 1 fredrik fredrik 98304 May 11 20:18 out
$ rm out
$ python2.4
>>> f = open("out", "w")
>>> f.write(100000*"x")
>>> ^D
$ ls -l out
-rw-rw-r-- 1 fredrik fredrik 100000 May 11 20:19 out
</F>
More information about the Python-list
mailing list