Always read all available lines from stdout and stderr

Should produce faster output.
This commit is contained in:
Gina Häußge 2016-02-11 10:27:07 +01:00
parent 3fb9248d2a
commit b5f40cfd69

View file

@ -124,34 +124,34 @@ class PipCaller(object):
all_stderr = []
try:
while p.returncode is None:
line = p.stderr.readline(timeout=0.5)
if line:
line = self._convert_line(line)
self._log_stderr(line)
all_stderr.append(line)
lines = p.stderr.readlines(timeout=0.5)
if lines:
lines = self._convert_lines(lines)
self._log_stderr(*lines)
all_stderr += lines
line = p.stdout.readline(timeout=0.5)
if line:
line = self._convert_line(line)
self._log_stdout(line)
all_stdout.append(line)
lines = p.stdout.readlines(timeout=0.5)
if lines:
lines = self._convert_lines(lines)
self._log_stdout(*lines)
all_stdout += lines
p.commands[0].poll()
finally:
p.close()
stderr = p.stderr.text
if stderr:
split_lines = map(self._convert_line, stderr.split("\n"))
self._log_stderr(*split_lines)
all_stderr += split_lines
lines = p.stderr.readlines()
if lines:
lines = map(self._convert_line, lines)
self._log_stderr(*lines)
all_stderr += lines
stdout = p.stdout.text
if stdout:
split_lines = map(self._convert_line, stdout.split("\n"))
self._log_stdout(*split_lines)
all_stdout += split_lines
lines = p.stdout.readlines()
if lines:
lines = map(self._convert_line, lines)
self._log_stdout(*lines)
all_stdout += lines
return p.returncode, all_stdout, all_stderr
@ -240,6 +240,10 @@ class PipCaller(object):
def _log_stderr(self, *lines):
self.on_log_stderr(*lines)
@staticmethod
def _convert_lines(lines):
return map(PipCaller._convert_line, lines)
@staticmethod
def _convert_line(line):
return to_unicode(_clean_ansi(line), errors="replace")