Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Track and print out the apps and clients that are inhibiting Gnome session actions like log out, user switching, suspending or idle/dpms/screensaver, under Linux.
Print out the apps and clients that are inhibiting session actions like log out, user switching, suspending or idle.
track_session_inhibitors &
Remember info about inhibitors and clients, for display when the are removed
describe flags with mnemonics. Consider using bitstring package:
1: Inhibit logging out
2: Inhibit user switching
4: Inhibit suspending the session or computer
8: Inhibit the session being marked as idle
import sys
import traceback
from gi.repository import GObject
import dbus
import dbus.mainloop.glib
import pynotify
import logging
__author__ = "Neal McBurnett <>"
__version__ = "0.1.0"
__date__ = "2012-07-12"
__copyright__ = "Copyright (c) 2012 Neal McBurnett"
__license__ = "GPL v3"
def inhibitor_dump(inhibitor_id):
status = "%s " % inhibitor_id
inhibitor = bus.get_object('org.gnome.SessionManager', inhibitor_id)
interface = inhibitor.Introspect()
# import pdb; pdb.set_trace() # to figure out if there is anything to show for InhibitorRemoved
if interface.count("org.gnome.SessionManager.Inhibitor") > 0:
clientId = inhibitor.GetClientId()
except dbus.exceptions.DBusException, e:
clientId = "(null)"
status += "flags=%x, x11id=%d: %s \"%s\" %s" % (inhibitor.GetFlags(), inhibitor.GetToplevelXid(), inhibitor.GetAppId(), inhibitor.GetReason(), clientId)
status += "(null)"
if len(sys.argv) <= 1:
n = pynotify.Notification ("SessionManager Inhibitor Watch", status) ()
return status
def client_dump(client_id):
status = "%s " % client_id
client = bus.get_object('org.gnome.SessionManager', client_id)
interface = client.Introspect()
# import pdb; pdb.set_trace() # to debug
if interface.count("org.gnome.SessionManager.Client") > 0:
# print client.GetAll('org.gnome.SessionManager') # why does this always fail with UnknownMethod: Method "GetAll" with signature "s" on interface "(null)"?
# Why does this always fail?
clientId = client.GetClientId()
except dbus.exceptions.DBusException, e:
clientId = "(null)"
#logging.exception("Exception with GetClientId")
status += "process=%d: %s \"%s\" %s" % (client.GetUnixProcessId(), client.GetAppId(), client.GetStatus(), clientId)
status += "(null)"
if len(sys.argv) <= 1:
n = pynotify.Notification ("SessionManager Client Watch", status) ()
return status
def session_inhibitor_signal_handler(id):
def session_client_signal_handler(id):
if __name__ == '__main__':
if len(sys.argv) >1:
# for now treat any argument as a request to just print current inhibitors and clients to stdout, and then exit
logfile = None
logfile = "/var/log/session_inhibitors"
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s\t%(message)s', filename = logfile, filemode='a' )"Start find_session_inhibitors")
if not pynotify.init ("summary-body"):
logging.error("pynotify.init failed")
sys.exit (1)
bus = dbus.SessionBus()
proxy = bus.get_object('org.gnome.SessionManager','/org/gnome/SessionManager')
blockers = proxy.GetInhibitors()
for objectpath in blockers:
clients = proxy.GetClients()
for objectpath in clients:
if len(sys.argv) >1:
bus.add_signal_receiver(session_inhibitor_signal_handler, "InhibitorAdded", "org.gnome.SessionManager")
bus.add_signal_receiver(session_inhibitor_signal_handler, "InhibitorRemoved", "org.gnome.SessionManager")
bus.add_signal_receiver(session_client_signal_handler, "ClientAdded", "org.gnome.SessionManager")
bus.add_signal_receiver(session_client_signal_handler, "ClientRemoved", "org.gnome.SessionManager")"Start listening for signals")
mainloop = GObject.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.