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

Unified Diff: mojo/devtools/common/devtoolslib/linux_shell.py

Issue 1301613003: Return partial output when shell.run_and_get_output time limit is hit. (Closed) Base URL: git@github.com:domokit/mojo.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
Index: mojo/devtools/common/devtoolslib/linux_shell.py
diff --git a/mojo/devtools/common/devtoolslib/linux_shell.py b/mojo/devtools/common/devtoolslib/linux_shell.py
index dedee5b3f5ccc487dce915ac940543a8e4c3b78a..a4a83a971a9a9fc3f4821305b9861b8076588b4c 100644
--- a/mojo/devtools/common/devtoolslib/linux_shell.py
+++ b/mojo/devtools/common/devtoolslib/linux_shell.py
@@ -4,6 +4,7 @@
import subprocess
import threading
+import tempfile
from devtoolslib import http_server
from devtoolslib.shell import Shell
@@ -44,23 +45,18 @@ class LinuxShell(Shell):
@overrides(Shell)
def run_and_get_output(self, arguments, timeout=None):
command = self.command_prefix + [self.executable_path] + arguments
- p = subprocess.Popen(command, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
+ output_file = tempfile.TemporaryFile()
+ p = subprocess.Popen(command, stdout=output_file, stderr=output_file)
- class Results:
- """Workaround for Python scoping rules that prevent assigning to variables
- from the outer scope.
- """
- output = None
+ wait_thread = threading.Thread(target=p.wait)
+ wait_thread.start()
+ wait_thread.join(timeout)
- def do_run():
- (Results.output, _) = p.communicate()
-
- run_thread = threading.Thread(target=do_run)
- run_thread.start()
- run_thread.join(timeout)
-
- if run_thread.is_alive():
+ did_time_out = False
+ if p.poll() is None:
+ did_time_out = True
p.terminate()
- return p.returncode, Results.output, True
- return p.returncode, Results.output, False
+ p.poll()
+ output_file.seek(0)
+ output = output_file.read()
+ return p.returncode, output, did_time_out
« no previous file with comments | « no previous file | mojo/devtools/common/devtoolslib/shell_unittest.py » ('j') | mojo/devtools/common/devtoolslib/shell_unittest.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698