Moving towards Python 3.0 (was Re: [Python-Dev] Speed up functioncalls) (original) (raw)

Glyph Lefkowitz glyph at divmod.com
Mon Jan 31 20:08:24 CET 2005


On Mon, 2005-01-31 at 08:51 -0800, Michael Chermside wrote:

However, remember that changing away from reference counting is a change to the semantics of CPython. Right now, people can (and often do) assume that objects which don't participate in a reference loop are collected as soon as they go out of scope. They write code that depends on this... idioms like:

>>> textoffile = open(filename, 'r').read() Perhaps such idioms aren't a good practice (they'd fail in Jython or in IronPython), but they ARE common. So we shouldn't stop using reference counting unless we can demonstrate that the alternative is clearly better. Of course, we'd also need to devise a way for extensions to cooperate (which is a problem Jython, at least, doesn't face).

I agree that the issue is highly subtle, but this reason strikes me as kind of bogus. The problem here is not that the semantics are really different, but that Python doesn't treat file descriptors as an allocatable resource, and therefore doesn't trigger the GC when they are exhausted.

As it stands, this idiom works most of the time, and if an EMFILE errno triggered the GC, it would always work.

Obviously this would be difficult to implement pervasively, but maybe it should be a guideline for alternative implementations to follow so as not to fall into situations where tricks like this one, which are perfectly valid both semantically and in regular python, would fail due to an interaction with the OS...?



More information about the Python-Dev mailing list