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 <tudor.marcu@intel.com>
This commit is contained in:
Tudor Marcu
2016-03-28 14:09:50 -07:00
parent 2d1f4a75cd
commit ef79a9ce59
+7 -5
View File
@@ -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