proc = subprocess.Popen(['cat', '-'], stdin=subprocess.PIPE, stdout=
    subprocess.PIPE)

def writer():
    for i in range(100000):
        proc.stdin.write('%d\n' % i)
proc.stdin.close()
thread = threading.Thread(target=writer)
thread.start()
for line in proc.stdout:
    sys.stdout.write(line)
thread.join()
proc.wait()
pipe large amount of data to stdin while using subprocess.Popen