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 """A utility to run functions with timeouts and retries.""" | 5 """A utility to run functions with timeouts and retries.""" |
6 # pylint: disable=W0702 | 6 # pylint: disable=W0702 |
7 | 7 |
8 import logging | 8 import logging |
9 import threading | 9 import threading |
10 import time | 10 import time |
11 import traceback | 11 import traceback |
12 | 12 |
13 from pylib.utils import reraiser_thread | 13 from devil.utils import reraiser_thread |
14 from pylib.utils import watchdog_timer | 14 from devil.utils import watchdog_timer |
15 | 15 |
16 | 16 |
17 class TimeoutRetryThread(reraiser_thread.ReraiserThread): | 17 class TimeoutRetryThread(reraiser_thread.ReraiserThread): |
18 def __init__(self, func, timeout, name): | 18 def __init__(self, func, timeout, name): |
19 super(TimeoutRetryThread, self).__init__(func, name=name) | 19 super(TimeoutRetryThread, self).__init__(func, name=name) |
20 self._watcher = watchdog_timer.WatchdogTimer(timeout) | 20 self._watcher = watchdog_timer.WatchdogTimer(timeout) |
21 self._expired = False | 21 self._expired = False |
22 | 22 |
23 def GetWatcher(self): | 23 def GetWatcher(self): |
24 """Returns the watchdog keeping track of this thread's time.""" | 24 """Returns the watchdog keeping track of this thread's time.""" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 try: | 158 try: |
159 thread_group = reraiser_thread.ReraiserThreadGroup([child_thread]) | 159 thread_group = reraiser_thread.ReraiserThreadGroup([child_thread]) |
160 thread_group.StartAll() | 160 thread_group.StartAll() |
161 thread_group.JoinAll(child_thread.GetWatcher()) | 161 thread_group.JoinAll(child_thread.GetWatcher()) |
162 return ret[0] | 162 return ret[0] |
163 except: | 163 except: |
164 child_thread.LogTimeoutException() | 164 child_thread.LogTimeoutException() |
165 if num_try > retries: | 165 if num_try > retries: |
166 raise | 166 raise |
167 num_try += 1 | 167 num_try += 1 |
OLD | NEW |