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 <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2019-05-30 08:40:20 +12:00
parent 378413299c
commit ca56e1c664

View File

@ -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()