def sync(src, dest, passwd):
    cmd = ['sshpass', '-p', passwd, 'rsync', '-avz', '--progress', src, dest]
p = Popen(cmd, stdout=PIPE)
line = ''
while True:
    c = p.stdout.read(1)
if not c:
    break
if c in ['\n', '\r']:
    print('rsync progress: %s' % line)
line = ''
How to write a polling function in Python?