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

0

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

tuxpoldo

Posted 2014-06-05T15:02:59.730

Reputation: 1

Answers

0

Traditionally, this is done using XSMP and libSM. If you ask a session manager to log out, it sends "SaveYourself" messages to all clients that have registered with it over XSMP.

The program doesn't get killed, though; it exits by itself when Xlib loses the connection to the X11 server. (I'm not sure if gtk has an option to disable that.)

user1686

Posted 2014-06-05T15:02:59.730

Reputation: 283 655

Any Idea on how to implement this in Python? I found nothing useful until now.... – tuxpoldo – 2014-07-05T13:52:08.720