diff options
author | Aníbal Limón <anibal.limon@linux.intel.com> | 2015-06-23 11:49:54 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-06-26 09:25:51 +0100 |
commit | 08c50d62b520c8405f034e3d7adeea89e06226ee (patch) | |
tree | 66a0f536f9bf5e0a2e1fb98bdb0da31a03429ea1 | |
parent | 524d92ed7b53bef933527095e82f378b934f25ef (diff) | |
download | openembedded-core-08c50d62b520c8405f034e3d7adeea89e06226ee.tar.gz openembedded-core-08c50d62b520c8405f034e3d7adeea89e06226ee.tar.bz2 openembedded-core-08c50d62b520c8405f034e3d7adeea89e06226ee.zip |
oe/utils.py: Add support for init/end helper functions in ThreadWorker.
Add init/end helper functions for ThreadWorker also pass ThreadWorker
as first argument to init/end/func functions this enables per-thread
storage handling.
classes/sstate.bbclass: Add thread_worker argument to checkstatus
function.
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/classes/sstate.bbclass | 2 | ||||
-rw-r--r-- | meta/lib/oe/utils.py | 17 |
2 files changed, 14 insertions, 5 deletions
diff --git a/meta/classes/sstate.bbclass b/meta/classes/sstate.bbclass index a80d1ced72..1e2d4f6fc0 100644 --- a/meta/classes/sstate.bbclass +++ b/meta/classes/sstate.bbclass @@ -739,7 +739,7 @@ def sstate_checkhashes(sq_fn, sq_task, sq_hash, sq_hashfn, d, siginfo=False): if localdata.getVar('BB_NO_NETWORK', True) == "1" and localdata.getVar('SSTATE_MIRROR_ALLOW_NETWORK', True) == "1": localdata.delVar('BB_NO_NETWORK') - def checkstatus(arg): + def checkstatus(thread_worker, arg): (task, sstatefile) = arg localdata2 = bb.data.createCopy(localdata) diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py index f0d3c14137..cee087fdfa 100644 --- a/meta/lib/oe/utils.py +++ b/meta/lib/oe/utils.py @@ -218,22 +218,30 @@ from threading import Thread class ThreadedWorker(Thread): """Thread executing tasks from a given tasks queue""" - def __init__(self, tasks): + def __init__(self, tasks, worker_init, worker_end): Thread.__init__(self) self.tasks = tasks self.daemon = True + self.worker_init = worker_init + self.worker_end = worker_end + def run(self): from Queue import Empty + if self.worker_init is not None: + self.worker_init(self) + while True: try: func, args, kargs = self.tasks.get(block=False) except Empty: + if self.worker_end is not None: + self.worker_end(self) break try: - func(*args, **kargs) + func(self, *args, **kargs) except Exception, e: print e finally: @@ -241,12 +249,13 @@ class ThreadedWorker(Thread): class ThreadedPool: """Pool of threads consuming tasks from a queue""" - def __init__(self, num_workers, num_tasks): + def __init__(self, num_workers, num_tasks, worker_init=None, + worker_end=None): self.tasks = Queue(num_tasks) self.workers = [] for _ in range(num_workers): - worker = ThreadedWorker(self.tasks) + worker = ThreadedWorker(self.tasks, worker_init, worker_end) self.workers.append(worker) def start(self): |