diff options
author | Yuqian Li <liyuqian@google.com> | 2018-04-27 17:52:56 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-04-30 11:42:09 +0000 |
commit | 58b90f7f1757bd70b836c9daeb8f1cf6c2cd660b (patch) | |
tree | 87e020e277fa7af57091e99ec6f5907174494d76 /tools/calmbench | |
parent | efb4d08dd43cd07e0e1d2f2d5819046259a5d340 (diff) |
Raise exceptions from child threads to the main thread
Bug: skia:7883
Change-Id: Ia71550b94867588c124e93eac347c67e35aa48e8
Reviewed-on: https://skia-review.googlesource.com/124380
Auto-Submit: Yuqian Li <liyuqian@google.com>
Commit-Queue: Eric Boren <borenet@google.com>
Reviewed-by: Eric Boren <borenet@google.com>
Diffstat (limited to 'tools/calmbench')
-rw-r--r-- | tools/calmbench/ab.py | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/tools/calmbench/ab.py b/tools/calmbench/ab.py index 22c28e23f0..5ca086a22b 100644 --- a/tools/calmbench/ab.py +++ b/tools/calmbench/ab.py @@ -29,6 +29,7 @@ import json import subprocess import shlex import multiprocessing +import traceback from argparse import ArgumentParser from multiprocessing import Process from threading import Thread @@ -39,7 +40,7 @@ from pdb import set_trace HELP = """ \033[31mPlease call calmbench.py to drive this script if you're not doing so. This script is not supposed to be used by itself. (At least, it's not easy to -use by itself.) +use by itself. The calmbench bots may use this script directly.) \033[0m """ @@ -124,6 +125,21 @@ def append_times_from_file(args, name, filename): add_time(args, name, bench, float(time_num), time_unit) +class ThreadWithException(Thread): + def __init__(self, target): + super(ThreadWithException, self).__init__(target = target) + self.exception = None + + def run(self): + try: + self._Thread__target(*self._Thread__args, **self._Thread__kwargs) + except BaseException as e: + self.exception = e + + def join(self, timeout=None): + super(ThreadWithException, self).join(timeout) + + class ThreadRunner: """Simplest and stupidiest threaded executer.""" def __init__(self, args): @@ -133,7 +149,7 @@ class ThreadRunner: def add(self, args, fn): if len(self.threads) >= args.threads: self.wait() - t = Thread(target = fn) + t = ThreadWithException(target = fn) t.daemon = True self.threads.append(t) t.start() @@ -158,12 +174,23 @@ class ThreadRunner: ts.start() for t in self.threads: - t.join() + t.join() + + exceptions = [] + for t in self.threads: + if t.exception: + exceptions.append(t.exception) + self.threads = [] if not self.concise: ts.join() + if len(exceptions): + for exc in exceptions: + print exc + raise exceptions[0] + def split_arg(arg): raw = shlex.split(arg) @@ -365,4 +392,5 @@ if __name__ == "__main__": except Exception as e: print e print HELP - raise + traceback.print_exc() + raise e |