Ecco quello che posso leggere nella documentazione del modulo python sottoprocesso:chiusura stdout di filodiffusione pitone sottoprocesso
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.
Io in realtà non capisco perché dobbiamo chiudere p1.stdout dopo aver creato p2. Quando viene eseguito esattamente il p1.stdout.close()? Cosa succede quando p2 non finisce mai? Cosa succede quando né p1 o p2 terminano?
Ciò è corretto, questo è importante se il primo processo potrebbe essere eseguito molto più a lungo del secondo processo. –