catching X client kills in Tkinter

Timothy Docker timd at macquarie.com.au
Tue Feb 29 17:13:00 EST 2000


Randall Hopper writes:

 >  |Is it possible to catch the failure of a Tkinter based application
 >  |when the server connection is closed (ie under X11 and unix).
 > 
 > For close (typically bound to the "X" window manager icon):
 > 
 >   top.protocol( 'WM_DELETE_WINDOW', MyCleanupFunct )
 > 
 > I don't know if you can catch an X kill (maybe with signal handlers, unless
 > it materializes as a SIGKILL or another uncatchable signal).

Unfortunately this doesn't catch the situation where the X server
exits, or forcible closes the socket connection (done byt the xkill
command). 

There seems to be no direct way to do this with Tkinter at present. At
the Xlib level, the only way to catch it is with the call

	XSetIOErrorHandler(...)

Unfortunately Xlib exits when (if) this call returns. I have seen
longjmp used to resolve this issue, but longjmp isn't practical in a
python environment. Nevertheless since I only want to clean up before
exiting, this is ok for me. Basically I just wrapped this function in
it's own python->C dynamic module, such that it calls a python
callback when an IO error occurs, before exiting.


Tim




More information about the Python-list mailing list