diff options
author | Christian Heimes <christian@cheimes.de> | 2007-12-31 03:07:24 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-12-31 03:07:24 (GMT) |
commit | 862543aa85249b46649b60da96743b4b14c6c83b (patch) | |
tree | 64bd6ad52d774e0170d22cd37efff937952240f3 | |
parent | c90584ecc171a71289c6860b1206ca8031bb96ca (diff) | |
download | cpython-862543aa85249b46649b60da96743b4b14c6c83b.zip cpython-862543aa85249b46649b60da96743b4b14c6c83b.tar.gz cpython-862543aa85249b46649b60da96743b4b14c6c83b.tar.bz2 |
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
-rw-r--r-- | Lib/site.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/site.py b/Lib/site.py index 4d64d20..3ba4212 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) |