Chromium Code Reviews| Index: build/android/pylib/utils/reraiser_thread.py |
| diff --git a/build/android/pylib/utils/reraiser_thread.py b/build/android/pylib/utils/reraiser_thread.py |
| index bde162c112e34fb9f1c951fcfc092bd98e730507..a5fd487bd2d897d603e11d50899718a7e4cd5073 100644 |
| --- a/build/android/pylib/utils/reraiser_thread.py |
| +++ b/build/android/pylib/utils/reraiser_thread.py |
| @@ -21,8 +21,16 @@ class TimeoutError(Exception): |
| class ReraiserThread(threading.Thread): |
| """Thread class that can reraise exceptions.""" |
| - def __init__(self, func, args=[], kwargs={}): |
| - super(ReraiserThread, self).__init__() |
| + def __init__(self, func, args=[], kwargs={}, name=None): |
| + """Initialize thread. |
| + |
| + Args: |
| + func: callable to call on a new thread. |
| + args: list of positional arguments for callable, defaults to empty. |
| + kwargs: dictionary of keyword arguments for callable, defaults to empty. |
| + name: thread name, defaults to Thread-N. |
| + """ |
| + super(ReraiserThread, self).__init__(name=name) |
| self.daemon = True |
| self._func = func |
| self._args = args |
| @@ -104,11 +112,11 @@ class ReraiserThreadGroup(object): |
| try: |
| self._JoinAll(watcher) |
| except TimeoutError: |
| - alive_thread_ids = (t.ident for t in self._threads if t.isAlive()) |
| - for thread_id in alive_thread_ids: |
| + alive_thread_ids = {t.name: t.ident for t in self._threads if t.isAlive()} |
|
frankf
2013/04/09 19:03:10
this is only in python 2.7
frankf
2013/04/09 19:03:10
You can just loop over this below.
|
| + for thread_name, thread_id in alive_thread_ids.iteritems(): |
| stack = sys._current_frames()[thread_id] |
| logging.critical('*' * 80) |
| - logging.critical('Stack dump for timed out ThreadId = %s', thread_id) |
| + logging.critical('Stack dump for timed out thread \'%s\'', thread_name) |
| logging.critical('*' * 80) |
| for filename, lineno, name, line in traceback.extract_stack(stack): |
| logging.critical('File: "%s", line %d, in %s', filename, lineno, name) |