p = Popen(cmd, bufsize=1, stdin=open(os.devnull), stdout=PIPE, stderr=STDOUT)
for line in iter(p.stdout.readline, ''):
    print(line, end=' ')
lines.append(line)
p.stdout.close()
Need to avoid subprocess deadlock without communicate