6

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?

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.