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>
This commit is contained in:
Aníbal Limón 2015-06-23 11:49:54 -05:00 committed by Richard Purdie
parent 3fa32158c4
commit 615b351bf4
2 changed files with 14 additions and 5 deletions

View File

@ -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)

View File

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