]> granicus.if.org Git - python/commitdiff
Allow interrupt only when executing user code in subprocess
authorKurt B. Kaiser <kbk@shore.net>
Tue, 9 Oct 2007 19:31:30 +0000 (19:31 +0000)
committerKurt B. Kaiser <kbk@shore.net>
Tue, 9 Oct 2007 19:31:30 +0000 (19:31 +0000)
Patch 1225 Tal Einat modified from IDLE-Spoon.

Lib/idlelib/NEWS.txt
Lib/idlelib/run.py

index 70799fb6449d6438ececd8e9d0154550612a0249..680712e57b9fcd91ffa1000ebb36bdac798ce458 100644 (file)
@@ -3,6 +3,9 @@ What's New in IDLE 2.6a1?
 
 *Release date: XX-XXX-200X*
 
+- Allow keyboard interrupt only when user code is executing in subprocess.
+  Patch 1225 Tal Einat (reworked from IDLE-Spoon).
+
 - configDialog cleanup. Patch 1730217 Tal Einat.
 
 - textView cleanup. Patch 1718043 Tal Einat.
index ae810c4ecc7c6b39d5ab590a6b5c3bbc8f171077..4eb64d6bd7d9027ed932fe3a97141e68deb3e6b6 100644 (file)
@@ -38,10 +38,11 @@ else:
 
 # Thread shared globals: Establish a queue between a subthread (which handles
 # the socket) and the main thread (which runs user code), plus global
-# completion and exit flags:
+# completion, exit and interruptable (the main thread) flags:
 
 exit_now = False
 quitting = False
+interruptable = False
 
 def main(del_exitfunc=False):
     """Start the Python execution server in a subprocess
@@ -280,9 +281,14 @@ class Executive(object):
         self.autocomplete = AutoComplete.AutoComplete()
 
     def runcode(self, code):
+        global interruptable
         try:
             self.usr_exc_info = None
-            exec code in self.locals
+            interruptable = True
+            try:
+                exec code in self.locals
+            finally:
+                interruptable = False
         except:
             self.usr_exc_info = sys.exc_info()
             if quitting:
@@ -296,7 +302,8 @@ class Executive(object):
             flush_stdout()
 
     def interrupt_the_server(self):
-        thread.interrupt_main()
+        if interruptable:
+            thread.interrupt_main()
 
     def start_the_debugger(self, gui_adap_oid):
         return RemoteDebugger.start_debugger(self.rpchandler, gui_adap_oid)