summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose Quaresma <quaresma.jose@gmail.com>2022-04-16 23:28:46 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-07-15 17:51:34 +0100
commit4161dbbbd6c446501b6ec750f5dbc7fb0296eac0 (patch)
tree8a7410719e6efa50e96e72125e4fa41118874b78
parent6421d3330c10868faf01084d4fdd1f3f9874f3bd (diff)
downloadpoky-4161dbbbd6c446501b6ec750f5dbc7fb0296eac0.tar.gz
oe/utils: remove the ThreadedPool
The ThreadedPool in OE-core is mainly because python2 doesn't have threaded pools but python2 is dead for some time now and python3 have a ThreadPoolExecutor. The only local in OE-core where this ThreadedPool is in use is on the sstate.bbclass that is ported to the python3 ThreadPoolExecutor. (From OE-Core rev: aa8fd5e7c2a1125895accfd55ce9320819a10959) Signed-off-by: Jose Quaresma <quaresma.jose@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oe/utils.py64
1 files changed, 0 insertions, 64 deletions
diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
index 46fc76c261..1ee947d584 100644
--- a/meta/lib/oe/utils.py
+++ b/meta/lib/oe/utils.py
@@ -473,70 +473,6 @@ def get_multilib_datastore(variant, d):
473 localdata.setVar("MLPREFIX", "") 473 localdata.setVar("MLPREFIX", "")
474 return localdata 474 return localdata
475 475
476#
477# Python 2.7 doesn't have threaded pools (just multiprocessing)
478# so implement a version here
479#
480
481from queue import Queue
482from threading import Thread
483
484class ThreadedWorker(Thread):
485 """Thread executing tasks from a given tasks queue"""
486 def __init__(self, tasks, worker_init, worker_end, name=None):
487 Thread.__init__(self, name=name)
488 self.tasks = tasks
489 self.daemon = True
490
491 self.worker_init = worker_init
492 self.worker_end = worker_end
493
494 def run(self):
495 from queue import Empty
496
497 if self.worker_init is not None:
498 self.worker_init(self)
499
500 while True:
501 try:
502 func, args, kargs = self.tasks.get(block=False)
503 except Empty:
504 if self.worker_end is not None:
505 self.worker_end(self)
506 break
507
508 try:
509 func(self, *args, **kargs)
510 except Exception as e:
511 # Eat all exceptions
512 bb.mainlogger.debug("Worker task raised %s" % e, exc_info=e)
513 finally:
514 self.tasks.task_done()
515
516class ThreadedPool:
517 """Pool of threads consuming tasks from a queue"""
518 def __init__(self, num_workers, num_tasks, worker_init=None, worker_end=None, name="ThreadedPool-"):
519 self.tasks = Queue(num_tasks)
520 self.workers = []
521
522 for i in range(num_workers):
523 worker = ThreadedWorker(self.tasks, worker_init, worker_end, name=name + str(i))
524 self.workers.append(worker)
525
526 def start(self):
527 for worker in self.workers:
528 worker.start()
529
530 def add_task(self, func, *args, **kargs):
531 """Add a task to the queue"""
532 self.tasks.put((func, args, kargs))
533
534 def wait_completion(self):
535 """Wait for completion of all the tasks in the queue"""
536 self.tasks.join()
537 for worker in self.workers:
538 worker.join()
539
540class ImageQAFailed(Exception): 476class ImageQAFailed(Exception):
541 def __init__(self, description, name=None, logfile=None): 477 def __init__(self, description, name=None, logfile=None):
542 self.description = description 478 self.description = description