From 1a4267a887904edec1eb045126e4c97321b017a9 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 12 Jul 2018 14:31:52 +0200 Subject: [PATCH] Print a '.' every 30 seconds when running a command. It will avoid travis-ci to kill the job because of the absence of output. --- kiwixbuild/utils.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/kiwixbuild/utils.py b/kiwixbuild/utils.py index b76dc5a..a02d33a 100644 --- a/kiwixbuild/utils.py +++ b/kiwixbuild/utils.py @@ -248,10 +248,23 @@ def run_command(command, cwd, context, buildEnv=None, env=None, input=None, cros kwargs['stdin'] = subprocess.PIPE process = subprocess.Popen(command, shell=True, cwd=cwd, env=env, stdout=log or sys.stdout, stderr=subprocess.STDOUT, **kwargs) if input: - process.communicate(input.encode()) - retcode = process.wait() - if retcode: - raise subprocess.CalledProcessError(retcode, command) + input = input.encode() + while True: + try: + if input is None: + process.wait(timeout=30) + else: + process.communicate(input, timeout=30) + except subprocess.TimeoutExpired: + # Either `wait` timeout (and `input` is None) or + # `communicate` timeout (and we must set `input` to None + # to not communicate again). + input = None + print('.', end='', flush=True) + else: + break + if process.returncode: + raise subprocess.CalledProcessError(process.returncode, command) finally: if log: log.close()