[PATCH] util.system: avoid buffering of subprocess output when it is piped
Yuya Nishihara
yuya at tcha.org
Tue Oct 14 13:57:01 UTC 2014
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1409413094 -7200
# Sat Aug 30 17:38:14 2014 +0200
# Node ID 114069ffd21cb7b70513975d2b4db0712169f500
# Parent cc4be0f3d54ce2cdbfe6d6c8bc25de74d07b437c
util.system: avoid buffering of subprocess output when it is piped
util.system() copies subprocess' output through pipe if output file is not
stdout. Because a file iterator has internal buffering, output won't be
flushed until enough data is available. Therefore, it could easily miss
important messages such as "waiting for lock".
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -543,7 +543,10 @@ def system(cmd, environ={}, cwd=None, on
proc = subprocess.Popen(cmd, shell=True, close_fds=closefds,
env=env, cwd=cwd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
- for line in proc.stdout:
+ while True:
+ line = proc.stdout.readline()
+ if not line:
+ break
out.write(line)
proc.wait()
rc = proc.returncode
More information about the Mercurial-devel
mailing list