[Tkinter-discuss] Tkinter and signal handling

Michael Lange klappnase at web.de
Sat Jan 15 21:48:31 CET 2011


Hi,

I encountered a strange problem with Tkinter and the handling of signals
(on debian linux, both with Python-2.5 / Tk-8.4 and  Python-2.6 / Tk-8.6).
The problem resembles much the one described in this old message:

http://web.archiveorange.com/archive/v/5H3d1OLg2fjze5McyfSL

A basic code example:

##########################

import Tkinter
import signal

root = Tkinter.Tk()

def handle_signal(signum, frame):
    print 'Caught signal # %d' % signum
signal.signal(2, handle_signal)

root.mainloop()

##########################

When I run this program from a terminal and hit Ctrl-C I would expect the
message to print immediately, however the callback is delayed until the
mouse enters the Tkinter window *or* the window receives keyboard focus
*or* thewindow is being (partially) obscured with another window.
The same effect happens when I do a kill -2 on the process from another
terminal.

What baffles me even more is that I have another Tkinter app here,
where the signal handling works flawlessly, however this is a complex app
with quite a bunch of modules, and I am not sure where to look for the
magic that makes it work there; in the few lines of code that define this
app's signal handling I cannot see any fundamental difference to the above
example.

Does anyone have a clue?

Thanks in advance

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Romulan women are not like Vulcan females.  We are not dedicated to
pure logic and the sterility of non-emotion.
		-- Romulan Commander, "The Enterprise Incident",
		   stardate 5027.3


More information about the Tkinter-discuss mailing list