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

Side by Side 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: Address Etienne's comments. 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 unified diff | Download patch
« no previous file with comments | « no previous file | mojo/devtools/common/devtoolslib/linux_shell_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 import subprocess 5 import subprocess
6 import threading 6 import threading
7 import tempfile
7 8
8 from devtoolslib import http_server 9 from devtoolslib import http_server
9 from devtoolslib.shell import Shell 10 from devtoolslib.shell import Shell
10 from devtoolslib.utils import overrides 11 from devtoolslib.utils import overrides
11 12
12 13
13 class LinuxShell(Shell): 14 class LinuxShell(Shell):
14 """Wrapper around Mojo shell running on Linux. 15 """Wrapper around Mojo shell running on Linux.
15 16
16 Args: 17 Args:
(...skipping 20 matching lines...) Expand all
37 pass 38 pass
38 39
39 @overrides(Shell) 40 @overrides(Shell)
40 def run(self, arguments): 41 def run(self, arguments):
41 command = self.command_prefix + [self.executable_path] + arguments 42 command = self.command_prefix + [self.executable_path] + arguments
42 return subprocess.call(command, stderr=subprocess.STDOUT) 43 return subprocess.call(command, stderr=subprocess.STDOUT)
43 44
44 @overrides(Shell) 45 @overrides(Shell)
45 def run_and_get_output(self, arguments, timeout=None): 46 def run_and_get_output(self, arguments, timeout=None):
46 command = self.command_prefix + [self.executable_path] + arguments 47 command = self.command_prefix + [self.executable_path] + arguments
47 p = subprocess.Popen(command, stdout=subprocess.PIPE, 48 output_file = tempfile.TemporaryFile()
48 stderr=subprocess.STDOUT) 49 p = subprocess.Popen(command, stdout=output_file, stderr=output_file)
49 50
50 class Results: 51 wait_thread = threading.Thread(target=p.wait)
51 """Workaround for Python scoping rules that prevent assigning to variables 52 wait_thread.start()
52 from the outer scope. 53 wait_thread.join(timeout)
53 """
54 output = None
55 54
56 def do_run(): 55 did_time_out = False
57 (Results.output, _) = p.communicate() 56 if p.poll() is None:
58 57 did_time_out = True
59 run_thread = threading.Thread(target=do_run)
60 run_thread.start()
61 run_thread.join(timeout)
62
63 if run_thread.is_alive():
64 p.terminate() 58 p.terminate()
65 return p.returncode, Results.output, True 59 p.poll()
66 return p.returncode, Results.output, False 60 output_file.seek(0)
61 output = output_file.read()
62 return p.returncode, output, did_time_out
OLDNEW
« no previous file with comments | « no previous file | mojo/devtools/common/devtoolslib/linux_shell_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698