def print_output(out, ntrim=80):
    for line in out:
        print(len(line))
if len(line) > ntrim:
    line = line[:ntrim - 2] + '..'
print(line.rstrip())
if __name__ == '__main__':
    p = Popen(['python', 'script.py'], stdin=PIPE, stdout=PIPE)
Thread(target=print_output, args=(p.stdout,)).start()
for s in ['abc', 'def', 'ab' * 10 ** 7, 'ghi']:
    print(s, file=p.stdin)
p.stdin.close()
sys.exit(p.wait())
python, подпроцесс: чтение вывода из подпроцесса