Skip to contentSkip to conversation

knotty, uihelper: Remove running_pids and lastpids

PATCH New Peter Kjellerstedt 1 participant 3 messages Oct 11, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 knotty, uihelper: Remove running_pids and lastpids

* lastpids has not been used for almost 10 years.
* There is no longer any need to use running_pids to keep track of the order the pids in running_tasks were added as dicts are guaranteed to remember the insertion order since Python 3.7.

---
 bitbake/lib/bb/ui/knotty.py   | 5 +----
 bitbake/lib/bb/ui/uihelper.py | 3 ---
 2 files changed, 1 insertion(+), 7 deletions(-)
bitbake/lib/bb/ui/knotty.py +1 -4
index 492ea20763..00258c80ff 100644
@@ -169,7 +169,6 @@ class TerminalFilter(object):
         self.stdinbackup = None
         self.interactive = sys.stdout.isatty()
         self.footer_present = False
-        self.lastpids = []
         self.lasttime = time.time()
         self.quiet = quiet
 
@@ -254,7 +253,6 @@ class TerminalFilter(object):
             return
         activetasks = self.helper.running_tasks
         failedtasks = self.helper.failed_tasks
-        runningpids = self.helper.running_pids
         currenttime = time.time()
         deltatime = currenttime - self.lasttime
 
@@ -283,7 +281,7 @@ class TerminalFilter(object):
         self._footer_buf.seek(0)
 
         tasks = []
-        for t in runningpids:
+        for t in activetasks.keys():
             start_time = activetasks[t].get("starttime", None)
             if start_time:
                 msg = "%s - %s (pid %s)" % (activetasks[t]["title"], self.elapsed(currenttime - start_time), activetasks[t]["pid"])
@@ -358,7 +356,6 @@ class TerminalFilter(object):
                     content = "%s: %s" % (tasknum, task)
                     print(content, file=self._footer_buf)
                 lines = lines + self.getlines(content)
-        self.lastpids = runningpids[:]
         self.lastcount = self.helper.tasknumber_current
 
         # Clear footer and Print buffer.
bitbake/lib/bb/ui/uihelper.py +0 -3
index e6983bd559..a223632471 100644
@@ -13,7 +13,6 @@ class BBUIHelper:
         self.needUpdate = False
         self.running_tasks = {}
         # Running PIDs preserves the order tasks were executed in
-        self.running_pids = []
         self.failed_tasks = []
         self.pidmap = {}
         self.tasknumber_current = 0
@@ -23,7 +22,6 @@ class BBUIHelper:
         # PIDs are a bad idea as they can be reused before we process all UI events.
         # We maintain a 'fuzzy' match for TaskProgress since there is no other way to match
         def removetid(pid, tid):
-            self.running_pids.remove(tid)
             del self.running_tasks[tid]
             if self.pidmap[pid] == tid:
                 del self.pidmap[pid]
@@ -35,7 +33,6 @@ class BBUIHelper:
                 self.running_tasks[tid] = { 'title' : "mc:%s:%s %s" % (event._mc, event._package, event._task), 'starttime' : time.time(), 'pid' : event.pid }
             else:
                 self.running_tasks[tid] = { 'title' : "%s %s" % (event._package, event._task), 'starttime' : time.time(), 'pid' : event.pid }
-            self.running_pids.append(tid)
             self.pidmap[event.pid] = tid
             self.needUpdate = True
         elif isinstance(event, bb.build.TaskSucceeded):
#1 lore raw

PATCH 2/3 knotty: Some improvements to TerminalFilter.updateFooter()

* Correct/improve a couple of comments.
* Iterate over the values (tasks) of activetasks rather than the keys (TIDs) as the TIDs were only used to lookup the tasks.

---
 bitbake/lib/bb/ui/knotty.py | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
bitbake/lib/bb/ui/knotty.py +14 -14
index 00258c80ff..6f03bf2faa 100644
@@ -260,16 +260,16 @@ class TerminalFilter(object):
             self.helper.needUpdate = True
             need_update = self.helper.needUpdate
         else:
-            # Do not let to update faster then _DEFAULT_PRINT_INTERVAL
+            # Do not update faster than _DEFAULT_PRINT_INTERVAL
             # to avoid heavy print() flooding.
             need_update = self.helper.needUpdate and (deltatime > self._DEFAULT_PRINT_INTERVAL)
 
-        if self.footer_present and (not need_update):
-            # Footer update is not need.
+        if self.footer_present and not need_update:
+            # Footer update is not needed.
             return
-        else:
-            # Footer update is need and store its "lasttime" value.
-            self.lasttime = currenttime
+ 
+        # Remember the time when the footer was last updated.
+        self.lasttime = currenttime
 
         self.helper.needUpdate = False
         if (not self.helper.tasknumber_total or self.helper.tasknumber_current == self.helper.tasknumber_total) and not len(activetasks):
@@ -281,16 +281,16 @@ class TerminalFilter(object):
         self._footer_buf.seek(0)
 
         tasks = []
-        for t in activetasks.keys():
-            start_time = activetasks[t].get("starttime", None)
+        for task in activetasks.values():
+            start_time = task.get("starttime", None)
             if start_time:
-                msg = "%s - %s (pid %s)" % (activetasks[t]["title"], self.elapsed(currenttime - start_time), activetasks[t]["pid"])
+                msg = "%s - %s (pid %s)" % (task["title"], self.elapsed(currenttime - start_time), task["pid"])
             else:
-                msg = "%s (pid %s)" % (activetasks[t]["title"], activetasks[t]["pid"])
-            progress = activetasks[t].get("progress", None)
+                msg = "%s (pid %s)" % (task["title"], task["pid"])
+            progress = task.get("progress", None)
             if progress is not None:
-                pbar = activetasks[t].get("progressbar", None)
-                rate = activetasks[t].get("rate", None)
+                pbar = task.get("progressbar", None)
+                rate = task.get("rate", None)
                 if not pbar or pbar.bouncing != (progress < 0):
                     if progress < 0:
                         pbar = BBProgress("0: %s" % msg, 100, widgets=[' ', progressbar.BouncingSlider(), ''], extrapos=3, resize_handler=self.sigwinch_handle)
@@ -299,7 +299,7 @@ class TerminalFilter(object):
                         pbar = BBProgress("0: %s" % msg, 100, widgets=[' ', progressbar.Percentage(), ' ', progressbar.Bar(), ''], extrapos=5, resize_handler=self.sigwinch_handle)
                         pbar.bouncing = False
                     pbar.fd = self._footer_buf
-                    activetasks[t]["progressbar"] = pbar
+                    task["progressbar"] = pbar
                 tasks.append((pbar, msg, progress, rate, start_time))
             else:
                 tasks.append(msg)
#2 lore raw

PATCH 3/3 knotty, teamcity, tinfoil: Only allow one process progress bar at once

In reply to Peter Kjellerstedt

In case a process progress bar (e.g., "Initialising tasks") is active when a new one (e.g., "Checking sstate mirror object availability") is started, then finish the first one before starting the second. Also ignore ProcessProgress and ProcessFinished events that are not for the currently active progress bar.

This also adds an id to BBProgress (initialized to the initial msg), which is not affected by calls to setmessage().

---
 bitbake/lib/bb/tinfoil.py     | 10 +++++-----
 bitbake/lib/bb/ui/knotty.py   | 12 +++++++-----
 bitbake/lib/bb/ui/teamcity.py | 14 +++++++++++---
 3 files changed, 23 insertions(+), 13 deletions(-)
bitbake/lib/bb/tinfoil.py +5 -5
index e7fbcbca0a..0a8950e730 100644
@@ -91,23 +91,23 @@ def wait_for(f):
                             if isinstance(event, bb.event.ProcessStarted):
                                 if self.quiet > 1:
                                     continue
+                                if parseprogress:
+                                    parseprogress,finish()
                                 parseprogress = bb.ui.knotty.new_progress(event.processname, event.total)
                                 parseprogress.start(False)
                                 continue
                             if isinstance(event, bb.event.ProcessProgress):
                                 if self.quiet > 1:
                                     continue
-                                if parseprogress:
+                                if parseprogress and parseprogress.id == event.processname:
                                     parseprogress.update(event.progress)
-                                else:
-                                    bb.warn("Got ProcessProgress event for something that never started?")
                                 continue
                             if isinstance(event, bb.event.ProcessFinished):
                                 if self.quiet > 1:
                                     continue
-                                if parseprogress:
+                                if parseprogress and parseprogress.id == event.processname:
                                     parseprogress.finish()
-                                parseprogress = None
+                                    parseprogress = None
                                 continue
                             if isinstance(event, bb.command.CommandCompleted):
                                 result = True
bitbake/lib/bb/ui/knotty.py +7 -5
index 6f03bf2faa..4bcf6bd12f 100644
@@ -39,6 +39,7 @@ interactive = sys.stdout.isatty()
 
 class BBProgress(progressbar.ProgressBar):
     def __init__(self, msg, maxval, widgets=None, extrapos=-1, resize_handler=None):
+        self.id = msg
         self.msg = msg
         self.extrapos = extrapos
         if not widgets:
@@ -84,6 +85,7 @@ class NonInteractiveProgress(object):
     fobj = sys.stdout
 
     def __init__(self, msg, maxval):
+        self.id = msg
         self.msg = msg
         self.maxval = maxval
         self.finished = False
@@ -886,23 +888,23 @@ def main(server, eventHandler, params, tf = TerminalFilter):
                 if params.options.quiet > 1:
                     continue
                 termfilter.clearFooter()
+                if parseprogress:
+                    parseprogress.finish()
                 parseprogress = new_progress(event.processname, event.total)
                 parseprogress.start(False)
                 continue
             if isinstance(event, bb.event.ProcessProgress):
                 if params.options.quiet > 1:
                     continue
-                if parseprogress:
+                if parseprogress and parseprogress.id == event.processname:
                     parseprogress.update(event.progress)
-                else:
-                    bb.warn("Got ProcessProgress event for someting that never started?")
                 continue
             if isinstance(event, bb.event.ProcessFinished):
                 if params.options.quiet > 1:
                     continue
-                if parseprogress:
+                if parseprogress and parseprogress.id == event.processname:
                     parseprogress.finish()
-                parseprogress = None
+                    parseprogress = None
                 continue
 
             # ignore
bitbake/lib/bb/ui/teamcity.py +11 -3
index 7eeaab8d63..3177f4aaf4 100644
@@ -200,6 +200,7 @@ def main(server, eventHandler, params):
         logger.error("XMLRPC Fault getting commandline: {0}".format(x))
         return 1
 
+    active_process = None
     active_process_total = None
     is_tasks_running = False
 
@@ -300,16 +301,23 @@ def main(server, eventHandler, params):
 
             if isinstance(event, bb.event.ProcessStarted):
                 if event.processname in ["Initialising tasks", "Checking sstate mirror object availability"]:
+                    if active_process:
+                        ui.progress(active_process, 100)
+                        ui.block_end()
+                    active_process = event.processname
                     active_process_total = event.total
                     ui.block_start(event.processname)
             if isinstance(event, bb.event.ProcessFinished):
                 if event.processname in ["Initialising tasks", "Checking sstate mirror object availability"]:
-                    ui.progress(event.processname, 100)
-                    ui.block_end()
+                    if active_process and active_process == event.processname:
+                        ui.progress(event.processname, 100)
+                        ui.block_end()
+                        active_process = None
             if isinstance(event, bb.event.ProcessProgress):
                 if event.processname in ["Initialising tasks",
                                          "Checking sstate mirror object availability"] and active_process_total != 0:
-                    ui.progress(event.processname, event.progress * 100 / active_process_total)
+                    if active_process and active_process == event.processname:
+                        ui.progress(event.processname, event.progress * 100 / active_process_total)
             if isinstance(event, bb.event.CacheLoadStarted):
                 ui.block_start("Loading cache")
             if isinstance(event, bb.event.CacheLoadProgress):