]> code.ossystems Code Review - openembedded-core.git/commitdiff
oe/utils: allow naming threads in ThreadedPool
authorRoss Burton <ross@burtonini.com>
Wed, 24 Nov 2021 17:15:27 +0000 (17:15 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 25 Nov 2021 21:53:44 +0000 (21:53 +0000)
When looking at logs involving thread pools it is useful if the threads
can be named.

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oe/utils.py

index cf65639647b6648747f0eae4e6bca81f74239043..7982b2b5113049f89c2cb014cf49143d78456448 100644 (file)
@@ -483,8 +483,8 @@ from threading import Thread
 
 class ThreadedWorker(Thread):
     """Thread executing tasks from a given tasks queue"""
-    def __init__(self, tasks, worker_init, worker_end):
-        Thread.__init__(self)
+    def __init__(self, tasks, worker_init, worker_end, name=None):
+        Thread.__init__(self, name=name)
         self.tasks = tasks
         self.daemon = True
 
@@ -515,13 +515,12 @@ class ThreadedWorker(Thread):
 
 class ThreadedPool:
     """Pool of threads consuming tasks from a queue"""
-    def __init__(self, num_workers, num_tasks, worker_init=None,
-            worker_end=None):
+    def __init__(self, num_workers, num_tasks, worker_init=None, worker_end=None, name="ThreadedPool-"):
         self.tasks = Queue(num_tasks)
         self.workers = []
 
-        for _ in range(num_workers):
-            worker = ThreadedWorker(self.tasks, worker_init, worker_end)
+        for i in range(num_workers):
+            worker = ThreadedWorker(self.tasks, worker_init, worker_end, name=name + str(i))
             self.workers.append(worker)
 
     def start(self):