[Python-Dev] Idle, site.py, and the release candidates
solipsis at pitrou.net
Sun Mar 31 12:01:50 CEST 2013
On Sat, 30 Mar 2013 22:34:32 -0400
Terry Jan Reedy <tjreedy at udel.edu> wrote:
> I do not know enough about other circumstances in which stdin.fileno
> would do something other than return 0 to be sure of what the proper fix
> would be.
> (I increasingly dislike bare excepts as they hide the
> thinking and knowledge of the original programmer.
You should learn to use the power of version control:
$ hg ann Lib/site.py
will tell you that the lines you mention come from the following
$ hg log -r 86358b43c8bb -vp
user: Christian Heimes <christian at cheimes.de>
date: Mon Dec 31 03:07:24 2007 +0000
Don't close sys.stdin with quit() if sys.stdin wraps fd 0. Otherwise it
will raise a warning: Lib/io.py:1221: RuntimeWarning: Trying to close
diff --git a/Lib/site.py b/Lib/site.py
@@ -247,7 +247,12 @@
# Shells like IDLE catch the SystemExit, but listen when
their # stdin wrapper is closed.
+ fd = -1
+ if hasattr(sys.stdin, "fileno"):
+ fd = sys.stdin.fileno()
+ if fd != 0:
+ # Don't close stdin if it wraps fd 0
In this case the original motivation seems obsolete:
>>> import sys
That said, if IDLE users expect those global functions, perhaps IDLE
should define its own ones rather than rely on site.py.
More information about the Python-Dev