From fb6337c625d50e7190e4b36eda5b98948a017b0b Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Fri, 4 Nov 2016 18:50:38 +0100 Subject: [PATCH] [modules/dnf] DNF module was not updating properly Due to name-clashing of the datetime module's "time" alias, time.sleep didn't work (as it was looked up from the i3bumblebee module), consequently, the DNF poll thread exited. While at it, "beautify" the thread cancelling a bit by waiting until the main thread is not running anymore. --- bumblebee/modules/dnf.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/bumblebee/modules/dnf.py b/bumblebee/modules/dnf.py index 0271665..bc40e94 100644 --- a/bumblebee/modules/dnf.py +++ b/bumblebee/modules/dnf.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import time import shlex import threading @@ -16,12 +18,26 @@ def description(): return "Checks DNF for updated packages and displays the number of /// pending updates." def get_dnf_info(obj): - while True: + + loops = 0 + + for thread in threading.enumerate(): + if thread.name == "MainThread": + main = thread + + while main.is_alive(): try: res = subprocess.check_output(shlex.split("dnf updateinfo")) except Exception as e: break + loops += 1 + time.sleep(1) + if loops < obj.interval(): + continue + + loops = 0 + security = 0 bugfixes = 0 enhancements = 0 @@ -47,13 +63,11 @@ def get_dnf_info(obj): obj.set("enhancements", enhancements) obj.set("other", other) - time.sleep(obj.interval()) - - class Module(bumblebee.module.Module): def __init__(self, output, args): super(Module, self).__init__(args) - self._interval = args[0] if args else 30*60 + + self._interval = int(args[0]) if args else 30*60 self._counter = {} self._thread = threading.Thread(target=get_dnf_info, args=(self,)) self._thread.start()