From ca56e1c664bbce55edd5d7954dc25ac9ad534619 Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Thu, 30 May 2019 08:40:20 +1200 Subject: [PATCH] Try to make running background commands more responsive Calling communicate() blocks the process; but since we're writing the output directly to a file and not sending any input we don't actually need to call communicate(), just poll() (so that we can check the returncode attribute). Subjectively this does appear to improve performance although it has not fixed the ConnectionResetError issues. Signed-off-by: Paul Eggleton --- layerindex/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/layerindex/utils.py b/layerindex/utils.py index c691964..2a1689b 100644 --- a/layerindex/utils.py +++ b/layerindex/utils.py @@ -309,7 +309,10 @@ def runcmd(cmd, destdir=None, printerr=True, outfile=None, logger=None, shell=Fa proc = subprocess.Popen(cmd, stdout=out, stderr=out, cwd=destdir, shell=shell) global child_pid child_pid = proc.pid - proc.communicate() + proc.poll() + while proc.returncode is None: + proc.poll() + time.sleep(0.05) if proc.returncode: out.seek(0) output = out.read()