How to let Linux Python application handle termination on user logout correctly?
- by tuxpoldo
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