[pypy-dev] What's wrong with >>> open(?xxx?, ?w?).write(?stuff?) ?

Jim Baker jbaker at zyasoft.com
Fri Aug 20 20:20:17 CEST 2010


Obviously please close the file, ideally using something like the
with-statement or at least finally. But for perhaps the convenience of
scripters, and the sorrow of everyone else ;), Jython will close the file
upon clean termination of the JVM via registering a closer of such files
with Runtime#addShutdownHook<http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)>

This is currently part of the most important outstanding
bug<http://bugs.jython.org/issue1327>in Jython 2.5.2, and something
that has to be resolved for 2.5.2 beta 2,
because of how it interacts with classloaders and prevents their class GC
upon reload (thus potentially exhausting permgen).

On Fri, Aug 20, 2010 at 8:06 AM, Armin Rigo <arigo at tunes.org> wrote:

> Hi Donny,
>
> On Fri, Aug 20, 2010 at 06:23:26AM -0400, Donny Viszneki wrote:
> > Armin: Sakesun used "del f" and it appears you did not. In Python
> > IIRC, an explicit call to del should kick off the finalizer to flush
> > and close the file!
>
> No, you are wrong.  Try for example:
>
>    >>> f = open('xxx')
>    >>> g = f
>    >>> del f
>
> After this, 'g' still refers to the file, and it is still open.
>
> If you want the file to be flushed and closed, then call 'f.close()' :-)
>
>
> A bientot,
>
> Armin.
> _______________________________________________
> pypy-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/pypy-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20100820/26c1f8d8/attachment.html>


More information about the Pypy-dev mailing list