Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Unified Diff: build/android/pylib/device/adb_wrapper.py

Issue 636273004: Make TimeoutRetryThread's stoppable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: do not catch CommandFailedError in _WaitFor Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils.py » ('j') | build/android/pylib/device/device_utils.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698