diff --git a/Lib/site.py b/Lib/site.py index 4d64d20ccf7..3ba42121f6b 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)