threading support in python

Jean-Paul Calderone exarkun at divmod.com
Wed Sep 6 22:46:22 CEST 2006


On 06 Sep 2006 13:29:33 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote:
>"sjdevnull at yahoo.com" <sjdevnull at yahoo.com> writes:
>> > We had that debate already (PEP 343).  Yes, there is some sloppy
>> > current practice by CPython users that relies on the GC to close the
>> > db conn.
>>
>> This point is unrelated to with or ref-counting.  Even the standard
>> library will close file objects when they are GC'd.
>
>I don't think so.  AFAIK, there is no such thing as "when they are
>GC'd" in the language spec.  There is, at best, "if they are GC'd",
>not "when".  You are not guaranteed that GC ever takes place.  At
>best, those destructors run when the application totally shuts down,
>as the process is about to exit, but I'm not sure whether the spec
>promises even that.
>

It doesn't.  Fortunately, the platform will close your files for you
when your process exits. ;)

>> If this is not acceptable, it's a major change;
>
>It is guaranteeing GC running at any particular time that would be a
>major change.  There is no such guarantee right now; there is just an
>implementation artifact in CPython that has led to careless habits
>among some users.

Actually, there is an API for instructing the GC how frequently to run,
in addition to the explicit API for causing the GC to run when you invoke
it.  See the gc module for more information.

Jean-Paul



More information about the Python-list mailing list