scan_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=
    subprocess.STDOUT)
while some_criterium:
    line = run_with_timeout(timeout, None, scan_process.stdout.readline)
if line is None:
    break
else:
    some_criterium = do_something(line)
timeout on subprocess readline in python