[Tkinter-discuss] Okay, this one really has me baffled -- KeyboardInterrupt signal not working!

Michael Lange klappnase at web.de
Thu Apr 14 11:29:10 CEST 2005


On Wed, 13 Apr 2005 16:24:51 -0400
Jared Cohen <Jared.Cohen at noaa.gov> wrote:

> 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:
> 

I guess you would have to send the keyboard interrupt signal to the compileString process
with
    os.kill(pid, 2)
where pid is of course the process id of the compileString process.

Best regards

Michael



More information about the Tkinter-discuss mailing list