summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoss Burton <ross@burtonini.com>2021-11-24 17:15:27 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-11-25 21:53:44 +0000
commit18342945b021608794d83ecf567afd43f4379b24 (patch)
tree0cec6404441a586243c324973824137eacf59c95
parent717e538e70f78d79ba7cec2797024af0dc91aeb0 (diff)
downloadopenembedded-core-contrib-18342945b021608794d83ecf567afd43f4379b24.tar.gz
oe/utils: allow naming threads in ThreadedPool
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>
-rw-r--r--meta/lib/oe/utils.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
index cf65639647..7982b2b511 100644
--- a/meta/lib/oe/utils.py
+++ b/meta/lib/oe/utils.py
@@ -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):