OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """ | 5 """ |
6 Function/method decorators that provide timeout and retry logic. | 6 Function/method decorators that provide timeout and retry logic. |
7 """ | 7 """ |
8 | 8 |
9 import functools | 9 import functools |
10 import os | 10 import os |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 timeout = timeout_func(*args, **kwargs) | 43 timeout = timeout_func(*args, **kwargs) |
44 retries = retries_func(*args, **kwargs) | 44 retries = retries_func(*args, **kwargs) |
45 if pass_values: | 45 if pass_values: |
46 kwargs['timeout'] = timeout | 46 kwargs['timeout'] = timeout |
47 kwargs['retries'] = retries | 47 kwargs['retries'] = retries |
48 def impl(): | 48 def impl(): |
49 return f(*args, **kwargs) | 49 return f(*args, **kwargs) |
50 try: | 50 try: |
51 return timeout_retry.Run(impl, timeout, retries) | 51 return timeout_retry.Run(impl, timeout, retries) |
52 except old_errors.WaitForResponseTimedOutError as e: | 52 except old_errors.WaitForResponseTimedOutError as e: |
53 raise device_errors.CommandTimeoutError(str(e)) | 53 raise device_errors.CommandTimeoutError(str(e)), None, ( |
| 54 sys.exc_info()[2]) |
54 except old_errors.DeviceUnresponsiveError as e: | 55 except old_errors.DeviceUnresponsiveError as e: |
55 raise device_errors.DeviceUnreachableError(str(e)) | 56 raise device_errors.DeviceUnreachableError(str(e)), None, ( |
| 57 sys.exc_info()[2]) |
56 except reraiser_thread.TimeoutError as e: | 58 except reraiser_thread.TimeoutError as e: |
57 raise device_errors.CommandTimeoutError(str(e)) | 59 raise device_errors.CommandTimeoutError(str(e)), None, ( |
| 60 sys.exc_info()[2]) |
58 return TimeoutRetryWrapper | 61 return TimeoutRetryWrapper |
59 | 62 |
60 | 63 |
61 def WithTimeoutAndRetries(f): | 64 def WithTimeoutAndRetries(f): |
62 """A decorator that handles timeouts and retries. | 65 """A decorator that handles timeouts and retries. |
63 | 66 |
64 'timeout' and 'retries' kwargs must be passed to the function. | 67 'timeout' and 'retries' kwargs must be passed to the function. |
65 | 68 |
66 Args: | 69 Args: |
67 f: The function to decorate. | 70 f: The function to decorate. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 The actual decorator. | 139 The actual decorator. |
137 """ | 140 """ |
138 def decorator(f): | 141 def decorator(f): |
139 def get_timeout(inst, *_args, **kwargs): | 142 def get_timeout(inst, *_args, **kwargs): |
140 return kwargs.get('timeout', getattr(inst, default_timeout_name)) | 143 return kwargs.get('timeout', getattr(inst, default_timeout_name)) |
141 def get_retries(inst, *_args, **kwargs): | 144 def get_retries(inst, *_args, **kwargs): |
142 return kwargs.get('retries', getattr(inst, default_retries_name)) | 145 return kwargs.get('retries', getattr(inst, default_retries_name)) |
143 return _TimeoutRetryWrapper(f, get_timeout, get_retries, pass_values=True) | 146 return _TimeoutRetryWrapper(f, get_timeout, get_retries, pass_values=True) |
144 return decorator | 147 return decorator |
145 | 148 |
OLD | NEW |