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:27:30 +0100 |
commit | 615b351bf4b28fd25f3bf15f72ab038ce37b89f7 (patch) | |
tree | 64f8a2e67df821ae5fcab47ec174abe3e50dd29e | |
parent | 3fa32158c45edf276197fa56466ed942ab70be09 (diff) | |
download | poky-615b351bf4b28fd25f3bf15f72ab038ce37b89f7.tar.gz |
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.
(From OE-Core rev: 08c50d62b520c8405f034e3d7adeea89e06226ee)
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): | |||
739 | if localdata.getVar('BB_NO_NETWORK', True) == "1" and localdata.getVar('SSTATE_MIRROR_ALLOW_NETWORK', True) == "1": | 739 | if localdata.getVar('BB_NO_NETWORK', True) == "1" and localdata.getVar('SSTATE_MIRROR_ALLOW_NETWORK', True) == "1": |
740 | localdata.delVar('BB_NO_NETWORK') | 740 | localdata.delVar('BB_NO_NETWORK') |
741 | 741 | ||
742 | def checkstatus(arg): | 742 | def checkstatus(thread_worker, arg): |
743 | (task, sstatefile) = arg | 743 | (task, sstatefile) = arg |
744 | 744 | ||
745 | localdata2 = bb.data.createCopy(localdata) | 745 | 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 | |||
218 | 218 | ||
219 | class ThreadedWorker(Thread): | 219 | class ThreadedWorker(Thread): |
220 | """Thread executing tasks from a given tasks queue""" | 220 | """Thread executing tasks from a given tasks queue""" |
221 | def __init__(self, tasks): | 221 | def __init__(self, tasks, worker_init, worker_end): |
222 | Thread.__init__(self) | 222 | Thread.__init__(self) |
223 | self.tasks = tasks | 223 | self.tasks = tasks |
224 | self.daemon = True | 224 | self.daemon = True |
225 | 225 | ||
226 | self.worker_init = worker_init | ||
227 | self.worker_end = worker_end | ||
228 | |||
226 | def run(self): | 229 | def run(self): |
227 | from Queue import Empty | 230 | from Queue import Empty |
228 | 231 | ||
232 | if self.worker_init is not None: | ||
233 | self.worker_init(self) | ||
234 | |||
229 | while True: | 235 | while True: |
230 | try: | 236 | try: |
231 | func, args, kargs = self.tasks.get(block=False) | 237 | func, args, kargs = self.tasks.get(block=False) |
232 | except Empty: | 238 | except Empty: |
239 | if self.worker_end is not None: | ||
240 | self.worker_end(self) | ||
233 | break | 241 | break |
234 | 242 | ||
235 | try: | 243 | try: |
236 | func(*args, **kargs) | 244 | func(self, *args, **kargs) |
237 | except Exception, e: | 245 | except Exception, e: |
238 | print e | 246 | print e |
239 | finally: | 247 | finally: |
@@ -241,12 +249,13 @@ class ThreadedWorker(Thread): | |||
241 | 249 | ||
242 | class ThreadedPool: | 250 | class ThreadedPool: |
243 | """Pool of threads consuming tasks from a queue""" | 251 | """Pool of threads consuming tasks from a queue""" |
244 | def __init__(self, num_workers, num_tasks): | 252 | def __init__(self, num_workers, num_tasks, worker_init=None, |
253 | worker_end=None): | ||
245 | self.tasks = Queue(num_tasks) | 254 | self.tasks = Queue(num_tasks) |
246 | self.workers = [] | 255 | self.workers = [] |
247 | 256 | ||
248 | for _ in range(num_workers): | 257 | for _ in range(num_workers): |
249 | worker = ThreadedWorker(self.tasks) | 258 | worker = ThreadedWorker(self.tasks, worker_init, worker_end) |
250 | self.workers.append(worker) | 259 | self.workers.append(worker) |
251 | 260 | ||
252 | def start(self): | 261 | def start(self): |