diff mbox series

[3/4] knotty: Improve shutdown handling

Message ID 20230111175058.1526619-3-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit af38345b91cfc8a6bb5c38f5753255e7635bfe2b
Headers show
Series [1/4] tinfoil: Don't wait for events indefinitely | expand

Commit Message

Richard Purdie Jan. 11, 2023, 5:50 p.m. UTC
There are three levels of shutdown, the initial "wait for current tasks",
then "stop current tasks" and "exit now". Change the code so that we don't
instantly exit after "stop current tasks" but allow the events to come
through from the server first. The new shutdown level allows that to then
be broken out of too.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/ui/knotty.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py
index 7370a1adfd..431baa15ef 100644
--- a/lib/bb/ui/knotty.py
+++ b/lib/bb/ui/knotty.py
@@ -631,7 +631,12 @@  def main(server, eventHandler, params, tf = TerminalFilter):
     termfilter = tf(main, helper, console_handlers, params.options.quiet)
     atexit.register(termfilter.finish)
 
-    while main.shutdown < 2:
+    # shutdown levels
+    # 0 - normal operation
+    # 1 - no new task execution, let current running tasks finish
+    # 2 - interrupting currently executing tasks
+    # 3 - we're done, exit
+    while main.shutdown < 3:
         try:
             if (lastprint + printinterval) <= time.time():
                 termfilter.keepAlive(printinterval)
@@ -644,7 +649,7 @@  def main(server, eventHandler, params, tf = TerminalFilter):
                         termfilter.clearFooter()
                         print("No reply after pinging server (%s, %s), exiting." % (str(error), str(ret)))
                         return_value = 3
-                        main.shutdown = 2
+                        main.shutdown = 3
                     lastevent = time.time()
                 if not parseprogress:
                     termfilter.updateFooter()
@@ -756,15 +761,15 @@  def main(server, eventHandler, params, tf = TerminalFilter):
                 if event.error:
                     errors = errors + 1
                     logger.error(str(event))
-                main.shutdown = 2
+                main.shutdown = 3
                 continue
             if isinstance(event, bb.command.CommandExit):
                 if not return_value:
                     return_value = event.exitcode
-                main.shutdown = 2
+                main.shutdown = 3
                 continue
             if isinstance(event, (bb.command.CommandCompleted, bb.cooker.CookerExit)):
-                main.shutdown = 2
+                main.shutdown = 3
                 continue
             if isinstance(event, bb.event.MultipleProviders):
                 logger.info(str(event))