![読み取り/待機デッドロック[閉じる]](https://linux33.com/image/70226/%E8%AA%AD%E3%81%BF%E5%8F%96%E3%82%8A%2F%E5%BE%85%E6%A9%9F%E3%83%87%E3%83%83%E3%83%89%E3%83%AD%E3%83%83%E3%82%AF%5B%E9%96%89%E3%81%98%E3%82%8B%5D.png)
私のプロセスは中止されました。master
次のようになります。
p=Popen(cmd, stdin=PIPE, stdout=PIPE)
for ....: # a few million
p.stdin.write(...)
p.stdin.close()
out = p.stdout.read()
p.stdout.close()
exitcode = p.wait()
child
次のようになります。
l = list()
for line in sys.stdin:
l.append(line)
sys.stdout.write(str(len(l)))
strace -p PID_master
ディスプレイがmaster
停止しましたwait4(PID_child,...)
。strate -p PID_child
ディスプレイがchild
停止しましたread(0,...)
。
どうすればいいですか? !
close
私がそうしたのにstdin
なぜまだchild
読んでいるのか? !
答え1
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()
children.py
import sys
l = list()
for line in sys.stdin:
l.append(line)
sys.stdout.write(str(len(l)))
実行してください:
$ python parent.py
99999
正常に動作しているようで、問題は他の場所にあるようです。