diff options
author | Just van Rossum <just@letterror.com> | 2003-05-09 08:58:02 (GMT) |
---|---|---|
committer | Just van Rossum <just@letterror.com> | 2003-05-09 08:58:02 (GMT) |
commit | eb64af9201a199499a9918529484096127bc0348 (patch) | |
tree | 510683dde050c28bb67c4e781a51766ddd79f1b5 /Mac | |
parent | 476736eed609ec7142a2c35a7c5fc9c15cffb03a (diff) | |
download | cpython-eb64af9201a199499a9918529484096127bc0348.zip cpython-eb64af9201a199499a9918529484096127bc0348.tar.gz cpython-eb64af9201a199499a9918529484096127bc0348.tar.bz2 |
add explicit support for cancelling a running script (CFM-based MacPython had this built-in)
Diffstat (limited to 'Mac')
-rw-r--r-- | Mac/Tools/IDE/PyEdit.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/Mac/Tools/IDE/PyEdit.py b/Mac/Tools/IDE/PyEdit.py index 64463c6..502f7c4 100644 --- a/Mac/Tools/IDE/PyEdit.py +++ b/Mac/Tools/IDE/PyEdit.py @@ -619,16 +619,39 @@ class Editor(W.Window): savedir = os.getcwd() os.chdir(dir) sys.path.insert(0, dir) - else: - cwdindex = None + self._scriptDone = False + if sys.platform == "darwin": + # On MacOSX, MacPython doesn't poll for command-period + # (cancel), so to enable the user to cancel a running + # script, we have to spawn a thread which does the + # polling. It will send a SIGINT to the main thread + # (in which the script is running) when the user types + # command-period. + from threading import Thread + t = Thread(target=self._userCancelledMonitor, + name="UserCancelledMonitor") + t.start() try: execstring(pytext, globals, locals, file, self.debugging, modname, self.profiling) finally: + self._scriptDone = True if self.path: os.chdir(savedir) del sys.path[0] + def _userCancelledMonitor(self): + import time + from signal import SIGINT + while not self._scriptDone: + if Evt.CheckEventQueueForUserCancel(): + # Send a SIGINT signal to ourselves. + # This gets delivered to the main thread, + # cancelling the running script. + os.kill(os.getpid(), SIGINT) + break + time.sleep(0.25) + def getenvironment(self): if self.path: file = self.path |