From ba892d9c50dd79776de90b6627260dd423b51e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Mr=C3=A1zek?= Date: Thu, 23 Nov 2023 14:08:22 +0100 Subject: [PATCH] Properly capture STDERR from Podman --- surveyor/podman.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/surveyor/podman.py b/surveyor/podman.py index 263a530..d4e07ca 100644 --- a/surveyor/podman.py +++ b/surveyor/podman.py @@ -1,5 +1,6 @@ import os import json +import select import time import subprocess import contextlib @@ -174,13 +175,18 @@ def invokePodmanCommandPoll(command, output): Invoke podman command and continuously output stdout and stderr via a callback """ command = podmanBaseCommand(command) - p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - for line in iter(p.stdout.readline, b''): - output(line.decode("utf-8")) - output(p.stdout.read().decode("utf-8")) + p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + while True: + readable, _, _ = select.select([p.stdout, p.stderr], [], [], 0.1) + for file in readable: + line = file.readline().decode("utf-8") + output(line) + if p.poll() is not None: + break exitcode = p.wait() if exitcode != 0: - raise PodmanError(f"{' '.join(command)}", "") + raise RuntimeError(f"{' '.join(command)}", "") def imageExists(name): """