From: Christian Heimes Date: Mon, 31 Dec 2007 03:07:24 +0000 (+0000) Subject: Don't close sys.stdin with quit() if sys.stdin wraps fd 0. Otherwise it will raise... X-Git-Tag: v3.0a3~273 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=862543aa85249b46649b60da96743b4b14c6c83b;p=thirdparty%2FPython%2Fcpython.git 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 unclosable fd --- diff --git a/Lib/site.py b/Lib/site.py index 4d64d20ccf74..3ba42121f6b0 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -247,7 +247,12 @@ def setquit(): # Shells like IDLE catch the SystemExit, but listen when their # stdin wrapper is closed. try: - sys.stdin.close() + fd = -1 + if hasattr(sys.stdin, "fileno"): + fd = sys.stdin.fileno() + if fd != 0: + # Don't close stdin if it wraps fd 0 + sys.stdin.close() except: pass raise SystemExit(code)