# HG changeset patch # User Brock Pytlik # Date 1226980240 28800 # Node ID 5a41c5c740dd1611d6a3c1984f0385e6ee7248ce # Parent 1f961ce9bc95cf105c4097d2c342e3804422603d 5171 Updatemanager eating 50% of the CPU diff -r 1f961ce9bc95 -r 5a41c5c740dd src/updatemanagernotifier.py --- a/src/updatemanagernotifier.py Mon Nov 17 16:19:53 2008 -0800 +++ b/src/updatemanagernotifier.py Mon Nov 17 19:50:40 2008 -0800 @@ -217,7 +217,6 @@ self.status_icon.set_visible(True) def check_for_updates(self): - self.set_last_check_time() image_directory = os.popen(IMAGE_DIR_COMMAND).readline().rstrip() if debug == True: print "image_directory: %s" % image_directory @@ -239,6 +238,8 @@ print "pkgs_to_be_updated: %d" % count if count: self.show_status_icon() + self.set_last_check_time() + self.schedule_next_check_for_checks() return False # This is copied from a similar function in packagemanager.py @@ -324,6 +325,19 @@ self.notify.set_hint_int32("x", x) self.notify.set_hint_int32("y", y) + def schedule_next_check_for_checks(self): + """This schedules the next time to wake up to check if it's + necessary to check for updates yet.""" + if self.time_until_next_check > DAILY_SECS or \ + self.time_until_next_check <= 0: + next_check_time = DAILY_SECS + else: + next_check_time = self.time_until_next_check + if debug == True: + print "scheduling next check: %s" % next_check_time + gobject.timeout_add(int(next_check_time * 1000), + self.do_next_check) + def do_next_check(self): if debug == True: print "Called do_next_check" @@ -332,13 +346,8 @@ if self.last_check_time == 0 or self.is_check_required(): gobject.idle_add(self.check_for_updates) else: - if self.time_until_next_check > DAILY_SECS: - next_check_time = DAILY_SECS - else: - next_check_time = self.time_until_next_check - gobject.timeout_add(int(next_check_time*1000), self.do_next_check) - return False - return True + self.schedule_next_check_for_checks() + return False def check_already_running(self): atom = gtk.gdk.atom_intern("UPDATEMANAGERNOTIFIER",