[Python-Dev] Destructors and Closing of File Objects
arigo at tunes.org
Mon Apr 29 16:42:38 CEST 2013
On Sat, Apr 27, 2013 at 4:39 AM, Nikolaus Rath <Nikolaus at rath.org> wrote:
> It's indeed very informative, but it doesn't fully address the question
> because of the _pyio module which certainly can't use any custom C code.
> Does that mean that when I'm using x = _pyio.BufferedWriter(), I could loose
> data in the write buffer when the interpreter exits without me calling
> x.close(), but when using x = io.BufferedWriter(), the buffer is
> guaranteed to get flushed?
I actually described the behavior of CPython 2 while not realizing
that CPython 3 silently dropped this guarantee. (I also never
realized that Jython/IronPython don't have the same guarantee; they
could, if they implement 'atexit', like we did in PyPy. That's
however more acceptable if the platform itself doesn't offer the
Anyway, it's a guarantee that the C offers, so personally I find it
reasonable to expect CPython files to offer it too; not offering it is
kind of saying that there is a feature of C that is actually present
at a higher level than the exact same feature in Python, which looks
backward to me.
Additionally, this might be introducing subtle bugs in programs when
porting them to Python 3.
However I realize that the two arguments presented above might not be
accepted as relevant. (http://bugs.python.org/issue17852)
More information about the Python-Dev