Friday, April 26, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 4209  / 3 Years ago, thu, october 14, 2021, 9:11:33

In a background Python script I need to detect, when the system just woke up from suspend. What is a good way that does not rely on a root script but rather on python modules such as DBus?



I'm new to dbus so I could really use some example code. From what I read it's related to



org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Resuming


Can anyone help me out with some code that connects the resuming signal to callback?


More From » python

 Answers
4

Here is some example code that answers my question:



#!/usr/bin/python
# This is some example code on howto use dbus to detect when the system returns
#+from hibernation or suspend.

import dbus # for dbus communication (obviously)
import gobject # main loop
from dbus.mainloop.glib import DBusGMainLoop # integration into the main loop

def handle_resume_callback():
print "System just resumed from hibernate or suspend"

DBusGMainLoop(set_as_default=True) # integrate into main loob
bus = dbus.SystemBus() # connect to dbus system wide
bus.add_signal_receiver( # defince the signal to listen to
handle_resume_callback, # name of callback function
'Resuming', # singal name
'org.freedesktop.UPower', # interface
'org.freedesktop.UPower' # bus name
)

loop = gobject.MainLoop() # define mainloop
loop.run() # run main loop


See the dbus-python tutorial.


[#35797] Saturday, October 16, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tionpromoti

Total Points: 14
Total Questions: 112
Total Answers: 113

Location: Tonga
Member since Tue, Nov 30, 2021
2 Years ago
;