From 8ad1cee657eed365b51aa3c7531ab50e6d04b402 Mon Sep 17 00:00:00 2001 From: "chase@chromium.org" Date: Mon, 16 Aug 2010 19:12:27 +0000 Subject: [PATCH] Flush more often in gclient's SubprocessCallAndFilter. Speed up flushing of output on platforms that may not flush as often as we expect (like Windows). Wait at least 10s between flushes to avoid overloading busy readers. BUG=none TEST=gclient flushes on Windows more often, regular gclient operations continue to work as expected Review URL: http://codereview.chromium.org/3140013 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@56217 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient_utils.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gclient_utils.py b/gclient_utils.py index 07a8aeba7..19a39a69d 100644 --- a/gclient_utils.py +++ b/gclient_utils.py @@ -280,6 +280,11 @@ def SubprocessCallAndFilter(command, shell=(sys.platform == 'win32'), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + # Do a flush of sys.stdout before we begin reading from the subprocess's + # stdout. + last_flushed_at = time.time() + sys.stdout.flush() + # Also, we need to forward stdout to prevent weird re-ordering of output. # This has to be done on a per byte basis to make sure it is not buffered: # normally buffering is done for each line, but if svn requests input, no @@ -296,9 +301,16 @@ def SubprocessCallAndFilter(command, sys.stdout.write(in_byte) if in_byte != '\n': in_line += in_byte - if in_byte == '\n' and filter_fn: - filter_fn(in_line) + if in_byte == '\n': + if filter_fn: + filter_fn(in_line) in_line = '' + # Flush at least 10 seconds between line writes. We wait at least 10 + # seconds to avoid overloading the reader that called us with output, + # which can slow busy readers down. + if (time.time() - last_flushed_at) > 10: + last_flushed_at = time.time() + sys.stdout.flush() in_byte = kid.stdout.read(1) rv = kid.wait()