[Tkinter-discuss] Okay, this one really has me baffled --
KeyboardInterrupt signal not working!
Jared Cohen
Jared.Cohen at noaa.gov
Wed Apr 13 22:24:51 CEST 2005
Thanks a bunch for everybody's help with the syntax highlighting
problem, but I finally got fed up with trying, so now I'm looking for a
good XML parser to do the work for me ;-)
Anyway, now there's a new problem. Part of my application executes a
system command, captures the standard input/output/error pipes using
"(stdin, stdout_err) = os.popen4(...)", and displays them to a Pmw
TextDialog.
Now then, this system command may take a long time to execute, so I want
the user to be able to abort the process if they decide it's taking too
long or if they realize they made a mistake. In essence, the output
dialog should function like a shell window, which means the user can
press Ctrl-C to send an interrupt signal. I *THOUGHT* I could do that by
adding an Abort button, which raises a KeyboardException. Here's the
full code snippet:
########################################################################################
def SetupOutputDialog(self):
self.outputDialog = Pmw.TextDialog(self.root,
title="Output",
text_state='disabled',
buttons=('OK', 'Abort'),
command=self.OutputButtonPress)
......
def OutputButtonPress(self, button):
if button == 'OK':
self.outputDialog.withdraw()
elif button == 'Abort':
raise KeyboardInterrupt
.....
(stdin, stdout_err) = os.popen4(compileString + " &")
s = stdout_err.readline()
while s != "":
self.outputDialog.appendtext(s)
self.outputDialog.update()
s = stdout_err.readline()
########################################################################################
Seems perfectly sound, right? But for some reason, the Abort button
doesn't seem to work right. When I press it, I get the following exception:
KeyboardInterrupt Exception in Tk callback
Function: <function <lambda> at 0x40ac9bc4> (type: <type 'function'>)
Args: ()
Traceback (innermost last):
File "/usr/lib/python2.3/site-packages/Pmw/Pmw_1_2/lib/PmwBase.py",
line 1747, in __call__
return apply(self.func, args)
File "/usr/lib/python2.3/site-packages/Pmw/Pmw_1_2/lib/PmwDialog.py",
line 153, in <lambda>
command=lambda self=self, name=name: self._doCommand(name))
File "/usr/lib/python2.3/site-packages/Pmw/Pmw_1_2/lib/PmwDialog.py",
line 132, in _doCommand
return command(name)
File "/home/jmc/projects/tkfre/src/freMainGui.py", line 361, in
OutputButtonPress
raise KeyboardInterrupt
KeyboardInterrupt:
That seems like the exception I was supposed to get.......but the
process didn't stop!!! It detected the interrupt signal, but it didn't
interrupt anything!
The wierd thing is, if I Alt-Tab back into the shell from which I
started this application, and actually type Ctrl-C there, THEN it works.
But I don't understand why raising the KeyboardInterrupt signal doesn't
seem to do anything! Can anyone help please?
More information about the Tkinter-discuss
mailing list