diff mbox series

cooker: Use event to terminate parser threads

Message ID 20221207142741.2130790-1-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit 2aed34e1d4bf24bba6263f168ff31b55b5fbe982
Headers show
Series cooker: Use event to terminate parser threads | expand

Commit Message

Richard Purdie Dec. 7, 2022, 2:27 p.m. UTC
From: Joshua Watt <JPEWhacker@gmail.com>

Uses an event to terminate the parser threads instead of a queue. This
is not only simpler, but saves about 500ms on shutdown time

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/cooker.py | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index 4be95dd7fb..7f232f2b36 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -2093,11 +2093,7 @@  class Parser(multiprocessing.Process):
         pending = []
         try:
             while True:
-                try:
-                    self.quit.get_nowait()
-                except queue.Empty:
-                    pass
-                else:
+                if self.quit.is_set():
                     break
 
                 if pending:
@@ -2194,7 +2190,7 @@  class CookerParser(object):
         if self.toparse:
             bb.event.fire(bb.event.ParseStarted(self.toparse), self.cfgdata)
 
-            self.parser_quit = multiprocessing.Queue(maxsize=self.num_processes)
+            self.parser_quit = multiprocessing.Event()
             self.result_queue = multiprocessing.Queue()
 
             def chunkify(lst,n):
@@ -2226,8 +2222,7 @@  class CookerParser(object):
         else:
             bb.error("Parsing halted due to errors, see error messages above")
 
-        for process in self.processes:
-            self.parser_quit.put(None)
+        self.parser_quit.set()
 
         # Cleanup the queue before call process.join(), otherwise there might be
         # deadlocks.
@@ -2257,10 +2252,6 @@  class CookerParser(object):
             if hasattr(process, "close"):
                 process.close()
 
-        self.parser_quit.close()
-        # Allow data left in the cancel queue to be discarded
-        self.parser_quit.cancel_join_thread()
-
         def sync_caches():
             for c in self.bb_caches.values():
                 c.sync()