From 98f80e30ba45822f5610dd5357833c1de9eee14c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sun, 15 Nov 2015 01:19:22 +0100 Subject: [PATCH] [fix] Update call_async_output to make use of start_async_file_reading --- moulinette/utils/process.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/moulinette/utils/process.py b/moulinette/utils/process.py index 52790c96..2765abbd 100644 --- a/moulinette/utils/process.py +++ b/moulinette/utils/process.py @@ -1,10 +1,11 @@ +import time import subprocess try: from pipes import quote # Python2 & Python3 <= 3.2 except ImportError: from shlex import quote # Python3 >= 3.3 -from .stream import NonBlockingStreamReader +from .stream import start_async_file_reading # Prevent to import subprocess only for common classes CalledProcessError = subprocess.CalledProcessError @@ -55,22 +56,16 @@ def call_async_output(args, callback, **kwargs): stderr=subprocess.STDOUT, **kwargs) # Wrap and get command output - stream = NonBlockingStreamReader(p.stdout) - while True: - line = stream.readline(True, 0.1) - if not line: - # Check if process has terminated - returncode = p.poll() - if returncode is not None: - break - else: + reader, queue = start_async_file_reading(p.stdout) + while not reader.eof(): + while not queue.empty(): + line = queue.get() try: callback(line.rstrip()) except: pass - stream.close() - - return returncode + reader.join() + return p.poll() # Call multiple commands -----------------------------------------------