prevent IDLE from trying to close when sys.stdin is reassigned (#17838)
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index e82ebf4..9cc009f 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -264,6 +264,11 @@
                 IOBinding.encoding)
         sys.stderr = PyShell.PseudoOutputFile(self.console, "stderr",
                 IOBinding.encoding)
+
+        # Keep a reference to stdin so that it won't try to exit IDLE if
+        # sys.stdin gets changed from within IDLE's shell. See issue17838.
+        self._keep_stdin = sys.stdin
+
         self.interp = self.get_remote_proxy("interp")
         rpc.RPCHandler.getresponse(self, myseq=None, wait=0.05)