OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Thread and ThreadGroup that reraise exceptions on the main thread.""" | 5 """Thread and ThreadGroup that reraise exceptions on the main thread.""" |
6 # pylint: disable=W0212 | 6 # pylint: disable=W0212 |
7 | 7 |
8 import logging | 8 import logging |
9 import sys | 9 import sys |
10 import threading | 10 import threading |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 def __init__(self, func, args=None, kwargs=None, name=None): | 43 def __init__(self, func, args=None, kwargs=None, name=None): |
44 """Initialize thread. | 44 """Initialize thread. |
45 | 45 |
46 Args: | 46 Args: |
47 func: callable to call on a new thread. | 47 func: callable to call on a new thread. |
48 args: list of positional arguments for callable, defaults to empty. | 48 args: list of positional arguments for callable, defaults to empty. |
49 kwargs: dictionary of keyword arguments for callable, defaults to empty. | 49 kwargs: dictionary of keyword arguments for callable, defaults to empty. |
50 name: thread name, defaults to Thread-N. | 50 name: thread name, defaults to Thread-N. |
51 """ | 51 """ |
| 52 if not name and func.__name__ != '<lambda>': |
| 53 name = func.__name__ |
52 super(ReraiserThread, self).__init__(name=name) | 54 super(ReraiserThread, self).__init__(name=name) |
53 if not args: | 55 if not args: |
54 args = [] | 56 args = [] |
55 if not kwargs: | 57 if not kwargs: |
56 kwargs = {} | 58 kwargs = {} |
57 self.daemon = True | 59 self.daemon = True |
58 self._func = func | 60 self._func = func |
59 self._args = args | 61 self._args = args |
60 self._kwargs = kwargs | 62 self._kwargs = kwargs |
61 self._ret = None | 63 self._ret = None |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 Args: | 219 Args: |
218 funcs: List of functions to perform on their own threads. | 220 funcs: List of functions to perform on their own threads. |
219 watcher: Watchdog object providing timeout, by default waits forever. | 221 watcher: Watchdog object providing timeout, by default waits forever. |
220 | 222 |
221 Returns: | 223 Returns: |
222 A list of return values in the order of the given functions. | 224 A list of return values in the order of the given functions. |
223 """ | 225 """ |
224 thread_group = ReraiserThreadGroup(ReraiserThread(f) for f in funcs) | 226 thread_group = ReraiserThreadGroup(ReraiserThread(f) for f in funcs) |
225 thread_group.StartAll(will_block=True) | 227 thread_group.StartAll(will_block=True) |
226 return thread_group.GetAllReturnValues(watcher=watcher) | 228 return thread_group.GetAllReturnValues(watcher=watcher) |
OLD | NEW |