[Python-checkins] python/dist/src/Mac/Tools/IDE PyEdit.py,1.42,1.43
jvr@users.sourceforge.net
jvr@users.sourceforge.net
Fri, 09 May 2003 01:58:04 -0700
Update of /cvsroot/python/python/dist/src/Mac/Tools/IDE
In directory sc8-pr-cvs1:/tmp/cvs-serv11643
Modified Files:
PyEdit.py
Log Message:
add explicit support for cancelling a running script (CFM-based MacPython had this built-in)
Index: PyEdit.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Tools/IDE/PyEdit.py,v
retrieving revision 1.42
retrieving revision 1.43
diff -C2 -d -r1.42 -r1.43
*** PyEdit.py 9 May 2003 08:33:58 -0000 1.42
--- PyEdit.py 9 May 2003 08:58:02 -0000 1.43
***************
*** 620,632 ****
os.chdir(dir)
sys.path.insert(0, dir)
! else:
! cwdindex = None
try:
execstring(pytext, globals, locals, file, self.debugging,
modname, self.profiling)
finally:
if self.path:
os.chdir(savedir)
del sys.path[0]
def getenvironment(self):
--- 620,655 ----
os.chdir(dir)
sys.path.insert(0, dir)
! 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):