Option to pause Variety when on battery power

Bug #1337417 reported by Peter Levi
20
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Variety
Triaged
Medium
Peter Levi

Bug Description

As confirmed already, Variety's use of Python 2's threading.Event.wait(timeout) causes enough CPU interruptions to be a power concern. Additionally changing wallpapers every X minutes or seconds is also taxing when on battery power.

We may provide an option to pause Variety entirely when on battery power.

For more detailed setup (e.g. not pause, but reduce the rate of change/download), we need to have support for profiles and let the user switch profiles when on battery - this is overkill for now. AND this won't actually kill the interruptions, which happen no matter what the wait() timeout is.

To listen for battery changes:
dbus and UPower
http://upower.freedesktop.org/docs/UPower.html#UPower::Changed

http://askubuntu.com/questions/183516/how-do-i-detect-when-my-system-wakes-up-from-suspend-via-dbus-or-similar-in-a-py
Monitor changed, and then check the "OnBattery" property.

Ivo Anjo (knuckles) wrote 56 minutes ago: #19
Ok, so to be more exact, I hacked the example, and it seems to work on my laptop. I ran with python -mtrace --trace and python is really doing nothing, and it doesn't show up on powertop.

Would something like this be an acceptable solution? :)

##########################

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

DBusGMainLoop(set_as_default=True) # integrate into main loob
bus = dbus.SystemBus() # connect to dbus system wide

proxy = bus.get_object('org.freedesktop.UPower','/org/freedesktop/UPower')
properties_manager = dbus.Interface(proxy, 'org.freedesktop.DBus.Properties')

def changed():
    print "Onbattery:" + str(properties_manager.Get('org.freedesktop.UPower', 'OnBattery'))

bus.add_signal_receiver( # defince the signal to listen to
    changed, # name of callback function
    'Changed', # singal name
    'org.freedesktop.UPower', # interface
    'org.freedesktop.UPower' # bus name
)

changed()

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

##########################

Revision history for this message
Ivo Anjo (knuckles) wrote :

You asked in the original bug report:

Can you give this a try with dbus.SessionBus() instead of dbus.SystemBus() (I'm not on a laptop now and don't have a battery...) - this is what Variety uses already for command line communication.

I tried it and it's not there. I guess that since it's a system-wide service it doesn't connect to the session dbus.
Also, while you can't try "unplugging" your desktop, the property is still there on a desktop, just always returns false.

Revision history for this message
James (james-r-barker) wrote :

Peter,
I'm not a developer, so apologies if this is a dumb question...

While watching the variety process in the system monitor or top, I have never seen the process to "sleep" -- it always shows as "running" and the CPU Time slowly ticks up. Additionally looking at powertop I see that the process frequently wakes up the CPU (which you already acknowledged above).

I have the app set to display a new local wallpaper image and new local quote every 1 hour. All effects and network options are disabled.

Should I see the process going to "sleep" at some point?
James

Variety 0.6.2
Ubuntu 16.10

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.