Question

I am working on a project where I need to inhibit power management (e.g. suspend) programatically. I am able to do so perfectly from Python:

import dbus
pm = dbus.SessionBus().get_object("org.freedesktop.PowerManagement", "/org/freedesktop/PowerManagement/Inhibit")
print(pm.HasInhibit()) # 0
inhibited = pm.Inhibit("Me", "I said so")
print(pm.HasInhibit()) # 1
pm.UnInhibit(inhibited)
print(pm.HasInhibit()) # 0

but not when using dbus-send from the command line:

$ dbus-send --print-reply --dest=org.freedesktop.PowerManagement /org/freedesktop/PowerManagement/Inhibit org.freedesktop.PowerManagement.Inhibit.HasInhibit
method return sender=:1.2 -> dest=:1.260969 reply_serial=2
  boolean false
$ dbus-send --print-reply --dest=org.freedesktop.PowerManagement /org/freedesktop/PowerManagement/Inhibit org.freedesktop.PowerManagement.Inhibit.Inhibit string:"Me" string:"I said so"
method return sender=:1.2 -> dest=:1.260972 reply_serial=2
  uint32 52
$ dbus-send --print-reply --dest=org.freedesktop.PowerManagement /org/freedesktop/PowerManagement/Inhibit org.freedesktop.PowerManagement.Inhibit.HasInhibit
method return sender=:1.2 -> dest=:1.260973 reply_serial=2
  boolean false

Why?

Was it helpful?

Solution

An inhibit is automatically released when when the process that set it dies.

So for one-shot commands inhibit will be released immediately.

I can't find the spec on Freedesktop.org, but my own tests under KDE and this page tend to confirm that this behavior is the same on most Session Managers / Power Managers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top