diff -r abbbe1f90635 Lib/idlelib/PyShell.py --- a/Lib/idlelib/PyShell.py Sun Mar 31 01:11:26 2013 -0500 +++ b/Lib/idlelib/PyShell.py Sun Mar 31 12:15:05 2013 -0500 @@ -1354,6 +1354,10 @@ self._line_buffer = line[size:] return line[:size] + def close(self): + # site.py's exit() and quit() calls sys.stdin.close() + self.shell.close() + usage_msg = """\ diff -r abbbe1f90635 Lib/site.py --- a/Lib/site.py Sun Mar 31 01:11:26 2013 -0500 +++ b/Lib/site.py Sun Mar 31 12:15:05 2013 -0500 @@ -349,15 +349,20 @@ def __call__(self, code=None): # Shells like IDLE catch the SystemExit, but listen when their # stdin wrapper is closed. - try: - fd = -1 - if hasattr(sys.stdin, "fileno"): + fd = -1 + if hasattr(sys.stdin, "fileno"): + try: fd = sys.stdin.fileno() - if fd != 0: - # Don't close stdin if it wraps fd 0 + except IOError: + pass + + if fd != 0: + # Don't close stdin if it wraps fd 0 + try: sys.stdin.close() - except: - pass + except: + pass + raise SystemExit(code) builtins.quit = Quitter('quit') builtins.exit = Quitter('exit')