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

Unified Diff: command_wrapper/bin/command_wrapper.py

Issue 10085001: Don't buffer stdout/stderr in command_wrapper.py (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/
Patch Set: whitespace change Created 8 years, 8 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: command_wrapper/bin/command_wrapper.py
===================================================================
--- command_wrapper/bin/command_wrapper.py (revision 132157)
+++ command_wrapper/bin/command_wrapper.py (working copy)
@@ -1,6 +1,6 @@
#!/usr/bin/python
#
-# Copyright (c) 2011 The Chromium Authors. All rights reserved.
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -25,6 +25,7 @@
LOG_TIMEOUT = 10
+ON_POSIX = 'posix' in sys.builtin_module_names
def LogCommand(options, command_id,
@@ -81,6 +82,15 @@
return wrapper['result']
+def Tee(fd, string_buffer, forward_fd):
+ """Read characters from fd and both append them to a buffer and write them to
+ forward_fd."""
+ for char in iter(lambda: fd.read(1), ''):
+ string_buffer += char
+ forward_fd.write(char)
+ fd.close()
+
+
def main(argv):
parser = optparse.OptionParser()
parser.add_option('-r', '--retries', dest='retries',
@@ -113,10 +123,24 @@
tm = time.time()
p = subprocess.Popen(cmd, shell=True,
stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- (p_stdout, p_stderr) = p.communicate()
- sys.stdout.write(p_stdout)
- sys.stderr.write(p_stderr)
+ stderr=subprocess.PIPE,
+ close_fds=ON_POSIX)
+ p_stdout = ''
+ t_stdout = threading.Thread(target=Tee,
+ args=(p.stdout, p_stdout, sys.stdout))
+ t_stdout.start()
+
+ p_stderr = ''
+ t_stderr = threading.Thread(target=Tee,
+ args=(p.stderr, p_stderr, sys.stderr))
+ t_stderr.start()
+
+ p.wait()
+
+ t_stdout.join()
+ t_stderr.join()
+
+
runtime = time.time() - tm
accept = RunWithTimeout(LOG_TIMEOUT, LogCommand,
options, command_id, r, cmd,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698