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

Unified Diff: build/android/pylib/cmd_helper.py

Issue 1284283002: [Android] Add partial output to TimeoutError raised in cmd_helper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « no previous file | build/android/pylib/perf/test_runner.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/cmd_helper.py
diff --git a/build/android/pylib/cmd_helper.py b/build/android/pylib/cmd_helper.py
index f8815531a56922b9db6734bef01392f7c2bea90f..1c2e9d94f0bf8b618f4357d26b59dc181e98add2 100644
--- a/build/android/pylib/cmd_helper.py
+++ b/build/android/pylib/cmd_helper.py
@@ -160,7 +160,14 @@ def GetCmdStatusAndOutput(args, cwd=None, shell=False):
class TimeoutError(Exception):
"""Module-specific timeout exception."""
- pass
+
+ def __init__(self, output=None):
+ super(TimeoutError, self).__init__()
+ self._output = output
+
+ @property
+ def output(self):
+ return self._output
def _IterProcessStdout(process, timeout=None, buffer_size=4096,
@@ -175,7 +182,7 @@ def _IterProcessStdout(process, timeout=None, buffer_size=4096,
end_time = (time.time() + timeout) if timeout else None
while True:
if end_time and time.time() > end_time:
- raise TimeoutError
+ raise TimeoutError()
read_fds, _, _ = select.select([child_fd], [], [], poll_interval)
if child_fd in read_fds:
data = os.read(child_fd, buffer_size)
@@ -216,10 +223,14 @@ def GetCmdStatusAndOutputWithTimeout(args, timeout, cwd=None, shell=False,
output = StringIO.StringIO()
process = Popen(args, cwd=cwd, shell=shell, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
- for data in _IterProcessStdout(process, timeout=timeout):
- if logfile:
- logfile.write(data)
- output.write(data)
+ try:
+ for data in _IterProcessStdout(process, timeout=timeout):
+ if logfile:
+ logfile.write(data)
+ output.write(data)
+ except TimeoutError:
+ raise TimeoutError(output.getvalue())
+
return process.returncode, output.getvalue()
« no previous file with comments | « no previous file | build/android/pylib/perf/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698