Scanning a file

Alex Martelli aleax at mail.comcast.net
Tue Nov 1 00:05:04 EST 2005


Steve Holden <steve at holdenweb.com> 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
<http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Objects/fi
leobject.c?rev=2.164.2.3&view=markup> :

"""
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) {
                Py_BEGIN_ALLOW_THREADS
                sts = (*f->f_close)(f->f_fp);
"""
etc.

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...?!


Alex



More information about the Python-list mailing list