From c1b28c4339454e0b895f531432d1ff971222a163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20Karlsen?= Date: Tue, 31 May 2016 05:42:45 +0200 Subject: make sure execcmd() handles large read buffers --- MgaRepo/util.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'MgaRepo/util.py') diff --git a/MgaRepo/util.py b/MgaRepo/util.py index ff71ce7..9008a59 100644 --- a/MgaRepo/util.py +++ b/MgaRepo/util.py @@ -71,11 +71,17 @@ def execcmd(*cmd, **kwargs): sys.stdout.write(data) output = error.getvalue() else: - proc.wait() - if proc.stdout is not None: - output = proc.stdout.read().decode('utf8') - if kwargs.get("strip", True): - output = output.rstrip() + # Make sure to avoid buffer getting full. + # Otherwise if ie. using proc.wait() both python + # and the process will just hang + while proc.poll() is None: + if proc.stdout is not None: + output += proc.stdout.read(8192).decode('utf8') + # Make sure that we've emptied the buffer entirely + output += proc.stdout.read().decode('utf8') + + if kwargs.get("strip", True): + output = output.rstrip() if (not kwargs.get("noerror")) and proc.returncode != 0: if kwargs.get("cleanerr"): -- cgit v1.2.1