From 183ff56dde67dae60620c880a4b09c867a0c32cd Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 2 Jul 2013 21:14:13 +0000 Subject: Don't block waiting for stderr when displaying subprocess output (mga#952) --- MgaRepo/util.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/MgaRepo/util.py b/MgaRepo/util.py index cc08274..62ac32e 100644 --- a/MgaRepo/util.py +++ b/MgaRepo/util.py @@ -7,6 +7,7 @@ import getpass import sys import os import re +import select from cStringIO import StringIO import httplib2 #import commands @@ -35,13 +36,20 @@ def execcmd(*cmd, **kwargs): of = pipe.stdout.fileno() ef = pipe.stderr.fileno() while True: - odata = os.read(of, 8192) - sys.stdout.write(odata) - edata = os.read(ef, 8192) - err.write(edata) - sys.stderr.write(edata) + r,w,x = select.select((of,ef), (), ()) + odata = None + if of in r: + odata = os.read(of, 8192) + sys.stdout.write(odata) + + edata = None + if ef in r: + edata = os.read(ef, 8192) + err.write(edata) + sys.stderr.write(edata) + status = pipe.poll() - if status is not None and not (odata and edata): + if status is not None and odata == "" and edata == "": break output = err.getvalue() else: -- cgit v1.2.1