parent.py
from subprocess import Popen, PIPE
cmd = ["python", "child.py"]
p=Popen(cmd, stdin=PIPE, stdout=PIPE)
for i in range(1,100000):
p.stdin.write("hello\n")
p.stdin.close()
out = p.stdout.read()
p.stdout.close()
print(out)
exitcode = p.wait()
child.py
import sys
l = list()
for line in sys.stdin:
l.append(line)
sys.stdout.write(str(len(l)))
Executando:
$ python parent.py
99999
Parece que isso funciona bem, então o problema deve estar em outro lugar.