How to let Linux Python application handle termination on user logout correctly?

Posted by tuxpoldo on Super User See other posts from Super User or by tuxpoldo
Published on 2014-06-05T15:02:59Z Indexed on 2014/06/05 15:27 UTC
Read the original article Hit count: 177

Filed under:
|
|
|
|

I have written a Linux GUI application in Python that needs to do some cleanup tasks before being terminated when the user logs out. Unfortunately it seems, that on logout, all applications are killed. I tried both to handle POSIX signals and DBUS notifications, but nothing worked. Any idea what I could have made wrong?

On application startup I register some termination handlers:

# create graceful shutdown mechanisms
signal.signal(signal.SIGTERM, self.on_signal_term)
self.bus = dbus.SessionBus()
self.bus.call_on_disconnection(self.on_session_disconnect)

When the user logs out, neither self.on_signal_term nor self.on_session_disconnect are called.

The problem occurs in several scenarios: Ubuntu 14.04 with Unity, Debian Wheezy with Gnome.

Full code: https://github.com/tuxpoldo/btsync-deb/tree/master/btsync-gui

© Super User or respective owner

Related posts about linux

Related posts about python