buildroot: continuously stream log data to monitor

All runners stopped calling `api.setup_stdio` (commit c40b414), and
thus all output of runners and also modules is now redirected to a
pipe (created via Popen and subprocess.PIPE for stdout).
Text was read from that pipe via `stdout.read(4096)`, which means
that it is now buffered in chunks of 4096, where it previously was
line buffered in the case that osbuild was run in the terminal and
--json was not specified. This is very annoying for anyone wanting
to follow osbuild's output in real-time.
Restore the previous behavior by using `os.read`, which should be
a small wrapper around read(3), which does not block until all the
requested data is available but returns early (short reads). This
means, new text will be forwarded as soon is it is available in the
pipe. Increase the read buffer to 32768 while at it, which is what
Popen is using in Python 3.9.
This commit is contained in:
Christian Kellner 2020-10-27 18:27:59 +01:00
parent f7949d9993
commit d9168ee625

View file

@ -232,11 +232,13 @@ class BuildRoot(contextlib.AbstractContextManager):
data = io.StringIO()
fd = proc.stdout.fileno()
while True:
txt = proc.stdout.read(4096)
if not txt:
buf = os.read(fd, 32768)
if not buf:
break
txt = buf.decode("utf-8")
data.write(txt)
monitor.log(txt)