diff -r 80b1dc3b3231 Lib/idlelib/run.py --- a/Lib/idlelib/run.py Sun Apr 21 04:08:18 2013 +0300 +++ b/Lib/idlelib/run.py Thu May 02 23:44:24 2013 -0500 @@ -293,6 +293,13 @@ sys.stderr = PyShell.PseudoOutputFile(self.console, "stderr", IOBinding.encoding) + # Follow sys.__stdxyz__ doc and prevent stream closure + # even if both sys references are rebound. See issue17838 + sys.__stdin__ = sys.stdin + sys.__stdout__ = sys.stdout + sys.__stderr__ = sys.stderr + self._keep_alive = (sys.stdin, sys.stdout, sys.stderr) + sys.displayhook = rpc.displayhook # page help() text to shell. import pydoc # import must be done here to capture i/o binding @@ -334,6 +341,8 @@ exec(code, self.locals) finally: interruptable = False + except SystemExit: + self.rpchandler._keep_alive[0].close() except: self.usr_exc_info = sys.exc_info() if quitting: