From ef79a9ce594a19344045bf3cc483ef08b8dd8b4a Mon Sep 17 00:00:00 2001 From: Tudor Marcu Date: Mon, 28 Mar 2016 14:09:50 -0700 Subject: [PATCH] Fix m4 infinite wait() If there are a lot of packages then the m4 output will overflow the max PIPE buffer, and the wait() will never finish. This patch reads the output in chunks and then creates a string of the entire output to pass to yum. Signed-off-by: Tudor Marcu --- bundle-chroot-builder.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bundle-chroot-builder.py b/bundle-chroot-builder.py index a346de8..e3c64ab 100755 --- a/bundle-chroot-builder.py +++ b/bundle-chroot-builder.py @@ -72,12 +72,14 @@ def read_config(args): def install_bundle(out_dir, postfix, bundle, bundles, yum_cmd): """Helper function to yum install a bundle""" - m4 = subprocess.Popen(["m4", bundles + "/" + bundle], cwd=bundles, stdout=subprocess.PIPE) - m4.wait() - pkgs = m4.stdout.readlines() + lines = [] + with subprocess.Popen(["m4", bundles + "/" + bundle], cwd=bundles, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p: + for line in p.stdout: + lines.append(line) + + pkgs = "".join(lines) to_install = [] - for pkg in pkgs: - pkg = pkg.decode("utf-8").strip() + for pkg in pkgs.splitlines(): # Don't add blank lines or lines with leading '#' if len(pkg) == 0 or pkg[0] == "#": continue