Index: build/android/pylib/device/adb_wrapper.py |
diff --git a/build/android/pylib/device/adb_wrapper.py b/build/android/pylib/device/adb_wrapper.py |
index f6ac660c276176c5bd75ded89fac57f63cf70243..2309182f8b572d57f7d7ddb603b6601a0c4e776a 100644 |
--- a/build/android/pylib/device/adb_wrapper.py |
+++ b/build/android/pylib/device/adb_wrapper.py |
@@ -10,10 +10,12 @@ should be delegated to a higher level (ex. DeviceUtils). |
import errno |
import os |
+import time |
from pylib import cmd_helper |
from pylib.device import decorators |
from pylib.device import device_errors |
+from pylib.utils import timeout_retry |
_DEFAULT_TIMEOUT = 30 |
@@ -44,15 +46,35 @@ class AdbWrapper(object): |
""" |
self._device_serial = str(device_serial) |
+ @classmethod |
+ def Wait(cls, secs): |
+ """Wait for the specified ammount of seconds. |
jbudorick
2014/10/30 02:27:03
nit: ammount -> amount
|
+ |
+ A drop-in replacement for time.sleep, which just waits for a number of |
+ seconds. After the wait is over, however, the method checks to see whether |
+ we're running under a timed-out thread and raises an exception if needed. |
+ |
+ Args: |
+ secs: the number of seconds to sleep |
+ """ |
+ timeout_thread = timeout_retry.GetTimeoutThread() |
+ if timeout_thread: |
+ remaining = timeout_thread.RemainingTime() |
+ if remaining is not None and remaining < secs: |
+ # no need to wait, we would time out anyway |
jbudorick
2014/10/30 02:27:02
nit: Add a log message here (probably at warning)
perezju
2014/10/30 18:44:44
This is much better now in my new proposal. An exc
|
+ timeout_thread.RaiseTimeout() |
+ time.sleep(secs) |
+ |
# pylint: disable=W0613 |
@classmethod |
@decorators.WithTimeoutAndRetries |
def _RunAdbCmd(cls, arg_list, timeout=None, retries=None, check_error=True): |
cmd = ['adb'] + arg_list |
- exit_code, output = cmd_helper.GetCmdStatusAndOutput(cmd) |
+ exit_code, output = cmd_helper.GetCmdStatusAndOutputWithTimeout( |
+ cmd, timeout_retry.GetTimeoutThread().RemainingTime()) |
if exit_code != 0: |
raise device_errors.AdbCommandFailedError( |
- cmd, 'returned non-zero exit code %s, output: %s' % |
+ cmd, 'returned non-zero exit code %d and output %r' % |
(exit_code, output)) |
# This catches some errors, including when the device drops offline; |
# unfortunately adb is very inconsistent with error reporting so many |