summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/utils.py
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2015-06-23 16:49:54 (GMT)
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-06-26 08:27:30 (GMT)
commit615b351bf4b28fd25f3bf15f72ab038ce37b89f7 (patch)
tree64f8a2e67df821ae5fcab47ec174abe3e50dd29e /meta/lib/oe/utils.py
parent3fa32158c45edf276197fa56466ed942ab70be09 (diff)
downloadpoky-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>
Diffstat (limited to 'meta/lib/oe/utils.py')
-rw-r--r--meta/lib/oe/utils.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
index f0d3c14..cee087f 100644
--- a/meta/lib/oe/utils.py
+++ b/meta/lib/oe/utils.py
@@ -218,22 +218,30 @@ from threading import Thread
218 218
219class ThreadedWorker(Thread): 219class 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
242class ThreadedPool: 250class 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):