Вот что я могу прочитать в документации модуля модуля Python Subprocess:
Replacing shell pipeline
output=`dmesg | grep hda`
==>
p1 = Popen(["dmesg"], stdout=PIPE)
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
output = p2.communicate()[0]
The p1.stdout.close() call after starting the p2 is important in order for p1
to receive a SIGPIPE if p2 exits before p1.
Я не совсем понимаю, почему мы должны закрыть P1.Stout после создания P2. Когда именно выполняется P1.Stdout.close ()? Что происходит, когда P2 никогда не заканчивается? Что происходит, когда и P1 или P2 End?