Bazaar on IronPython

Andrew Bennetts andrew.bennetts at canonical.com
Mon Jun 29 08:54:36 BST 2009


Martin Pool wrote:
> 2009/6/29 Andrew Bennetts <andrew.bennetts at canonical.com>:
[...]
> > And, judging from the patch, we sometimes open files (like config files)
> > without explicitly closing them, relying on garbage collection to do it.
> 
> I think those are just bugs and we should close them from finally
> blocks.  Our coding standards (or at least common practice in reviews)
> is to insist that people do.
> 
> I suppose this means that IronPython will not close files from gc?

My understanding is that IronPython will, but that gc happens at different
(and often later) times to CPython.  The big difference is there's no
refcounts, just the periodic (or background?) collector, so the “refcount of
X must be zero here therefore X has been cleaned up” assumption no longer
holds.

So in CPython you can get mostly-deterministic behaviour in simple cases
because you know things like that when a function returns any otherwise
unreferenced locals (e.g. a file handle) that will local be cleaned up (e.g.
the file handle is closed).  In IronPython (and Jython, and perhaps the
Unladen Swallow experiment, and probably PyPy) that object may get collected
arbitrarily later.  So you'll get “file already in use” bugs on Windows, and
potentially similar issues with other resources like TCP ports, but I think
files are the most common practical problem people encounter, because it's
so easy to just do “some_func(open(a_filename))” and assume the file will be
closed immediately afterwards.

-Andrew.




More information about the bazaar mailing list