diff Lib/idlelib/PyShell.py @ 83073:0be85a7fc839 3.3

#14254: IDLE now handles readline correctly across shell restarts.
author Roger Serwy <roger.serwy@gmail.com>
date Wed, 03 Apr 2013 00:42:24 -0500
parents d759b7bc9785
children d3c67e2fc68c 4b4f142befea
line wrap: on
line diff
--- a/Lib/idlelib/PyShell.py	Tue Apr 02 22:39:39 2013 -0500
+++ b/Lib/idlelib/PyShell.py	Wed Apr 03 00:42:24 2013 -0500
@@ -458,6 +458,7 @@
             self.display_no_subprocess_error()
             return None
         self.transfer_path(with_cwd=with_cwd)
+        console.stop_readline()
         # annotate restart in shell window and mark it
         console.text.delete("iomark", "end-1c")
         if was_executing:
@@ -896,6 +897,7 @@
     canceled = False
     endoffile = False
     closing = False
+    _stop_readline_flag = False
 
     def set_warning_stream(self, stream):
         global warning_stream
@@ -971,8 +973,7 @@
                 parent=self.text)
             if response is False:
                 return "cancel"
-        if self.reading:
-            self.top.quit()
+        self.stop_readline()
         self.canceled = True
         self.closing = True
         # Wait for poll_subprocess() rescheduling to stop
@@ -1027,6 +1028,12 @@
         tkinter._default_root = None # 03Jan04 KBK What's this?
         return True
 
+    def stop_readline(self):
+        if not self.reading:  # no nested mainloop to exit.
+            return
+        self._stop_readline_flag = True
+        self.top.quit()
+
     def readline(self):
         save = self.reading
         try:
@@ -1034,6 +1041,9 @@
             self.top.mainloop()  # nested mainloop()
         finally:
             self.reading = save
+        if self._stop_readline_flag:
+            self._stop_readline_flag = False
+            return ""
         line = self.text.get("iomark", "end-1c")
         if len(line) == 0:  # may be EOF if we quit our mainloop with Ctrl-C
             line = "\n"