p = subprocess.Popen('ls;sleep 10', shell=True, stdout=subprocess.PIPE,
    stderr=subprocess.PIPE)
rc = p.poll()
while rc != 0:
    while True:
        line = p.stdout.readline()
if not line:
    break
print(line)
rc = p.poll()
assert rc == 0
Getting progress message from a subprocess