mirror of
https://git.yoctoproject.org/poky
synced 2026-06-01 00:59:48 +00:00
lib/oe/utils: Handle exceptions in multiprocess_exec
Currently exceptions that happen in pool commands are ignored. Any errors would be printed on the console but everything else is silent. Switch to use pool.map_async which allows for an error_callback which we can use to detect exceptions and make sure these errors are handled. (From OE-Core rev: 7f2f9b3ff011b340b5d23bb7c47b12c357dc9f02) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
+13
-8
@@ -224,25 +224,30 @@ def multiprocess_exec(commands, function):
|
|||||||
def init_worker():
|
def init_worker():
|
||||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||||
|
|
||||||
|
fails = []
|
||||||
|
|
||||||
|
def failures(res):
|
||||||
|
fails.append(res)
|
||||||
|
|
||||||
nproc = min(multiprocessing.cpu_count(), len(commands))
|
nproc = min(multiprocessing.cpu_count(), len(commands))
|
||||||
pool = bb.utils.multiprocessingpool(nproc, init_worker)
|
pool = bb.utils.multiprocessingpool(nproc, init_worker)
|
||||||
imap = pool.imap(function, commands)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = list(imap)
|
mapresult = pool.map_async(function, commands, error_callback=failures)
|
||||||
|
|
||||||
pool.close()
|
pool.close()
|
||||||
pool.join()
|
pool.join()
|
||||||
results = []
|
results = mapresult.get()
|
||||||
for result in res:
|
|
||||||
if result is not None:
|
|
||||||
results.append(result)
|
|
||||||
return results
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pool.terminate()
|
pool.terminate()
|
||||||
pool.join()
|
pool.join()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
if fails:
|
||||||
|
raise fails[0]
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
def squashspaces(string):
|
def squashspaces(string):
|
||||||
import re
|
import re
|
||||||
return re.sub("\s+", " ", string).strip()
|
return re.sub("\s+", " ", string).strip()
|
||||||
|
|||||||
Reference in New Issue
Block a user