oe/utils: allow naming threads in ThreadedPool

When looking at logs involving thread pools it is useful if the threads
can be named.

(From OE-Core rev: 18342945b021608794d83ecf567afd43f4379b24)

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ross Burton 2021-11-24 17:15:27 +00:00 committed by Richard Purdie
parent cd91af372f
commit 1fb99950a2

View 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):