Scanning a file

Alex Martelli aleax at
Tue Nov 1 06:05:04 CET 2005

Steve Holden <steve at> wrote:
> > The runtime knows it is doing it.  Please allow the runtime to tell me
> > what it knows it is doing.  Thanks.
> In point oif fact I don't believe the runtime does any such thing 
> (though I must admit I haven't checked the source, so you may prove me
> wrong).
> As far as I know, Python simply relies on the opreating system to close
> files left open at the end of the program.

Nope, see
leobject.c?rev=> :

static void
file_dealloc(PyFileObject *f)
        int sts = 0;
        if (f->weakreflist != NULL)
                PyObject_ClearWeakRefs((PyObject *) f);
        if (f->f_fp != NULL && f->f_close != NULL) {
                sts = (*f->f_close)(f->f_fp);

Exactly how the OP wants to "allow the runtime to tell [him] what it
knows it is doing", that is not equivalent to reading the freely
available sources of that runtime, is totally opaque to me, though.

"The runtime" (implementation of built-in object type `file`) could be
doing or not doing a bazillion things (in its ..._dealloc function as
well as many other functions), up to and including emailing the OP's
cousin if it detects the OP is up later than his or her bedtime -- the
language specs neither mandate nor forbid such behavior.  How, exactly,
does the OP believe the language specs should "allow" (presumably,
REQUIRE) ``the runtime'' to communicate the sum total of all that it's
doing or not doing (beyond whatever the language specs themselves may
require or forbid it to do) on any particular occasion...?!


More information about the Python-list mailing list