[Python-bugs-list] [Bug #110616] source file stays open after parsing is done (PR#209)

noreply@sourceforge.net noreply@sourceforge.net
Sun, 27 Aug 2000 12:20:25 -0700


Bug #110616, was updated on 2000-Jul-31 14:06
Here is a current snapshot of the bug.

Project: Python
Category: Parser/Compiler
Status: Closed
Resolution: Fixed
Bug Group: None
Priority: 5
Summary: source file stays open after parsing is done (PR#209)

Details: Jitterbug-Id: 209
Submitted-By: Guido van Rossum <guido@python.org>
Date: Tue, 22 Feb 2000 10:42:17 -0500
Version: None
OS: None

The post below is evidence that there is a real need to close the
source file sooner than when the program execution is over.
Unfortunately, as Martin points out, this requires changing function
signatures (in the sense that the behaviors change).

The close-on-exec solution is not good enough; apart from the
portability issue it also doesn't solve other problems caused by
keeping the file open too long.

--Guido van Rossum (home page: http://www.python.org/~guido/)

------- Forwarded Message

Date:    Mon, 21 Feb 2000 19:00:32 +0100
From:    Martin von Loewis <loewis@informatik.hu-berlin.de>
To:      aliberi@acutronic.com
cc:      help@python.org, guido@CNRI.Reston.VA.US
Subject: Re: [Python-Help] execve

> I tried to submit the below report via the web interface, but kept getting
> the folowing message:
> 
>     The system encountered a fatal error
> 
>     After command:
>     Received:
> 
>     The last error code was: Connection refused
> 
> So, the bug report is below.  Thanks.

Thanks for your report. It looks like Python is not closing the file
descriptor of the script being executed. Please have a look at
Py_Main, where fp is the file descriptor of the script being executed
(potentially stdin). That is passed to PyRun_AnyFile, which eventually
calls the parser to read the file. When PyRun_AnyFile returns, the
file is closed if it is not stdin (or, rather, does not have a name).

Unfortunately, if the script performs exec, that file descriptor is
still open.

I see two solutions:
a) close the file after it has been parsed, before execution starts.
   That appears to be the Right Way (TM), but requires changes to the
   signatures of a number of functions.
b) set the close-on-exec flag for the script. That will automagically
   close it when necessary, but doing so is not very portable. It will
   probably work on both Linux and LynxOS, so you may consider fixing
   it that way yourself.

Good luck,
Martin

P.S. CC'ed to Guido for inspection.

------- End of Forwarded Message



====================================================================
Audit trail:
Wed Feb 23 21:30:38 2000	guido	moved from incoming to open

Follow-Ups:

Date: 2000-Aug-27 12:20
By: gvanrossum

Comment:
Fixed as follows:

Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
PyRun_FileEx().  These are the same as their non-Ex counterparts but
have an extra argument, a flag telling them to close the file when
done.

Then this is used by Py_Main() and execfile() to close the file after
it is parsed but before it is executed.

-------------------------------------------------------

For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=110616&group_id=5470