From d9168ee6251b537addb4ffd9f9ebbed9b9f4278b Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 27 Oct 2020 18:27:59 +0100 Subject: [PATCH] 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. --- osbuild/buildroot.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/osbuild/buildroot.py b/osbuild/buildroot.py index 05859038..bcce4c69 100644 --- a/osbuild/buildroot.py +++ b/osbuild/buildroot.py @@ -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)