在子进程模块的Python 2.7文档中,我找到了以下代码段:
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]
Run Code Online (Sandbox Code Playgroud)
资料来源:https://docs.python.org/2/library/subprocess.html#replacing-shell-pipeline
我不明白这一行: p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
这里p1.stdout正在关闭.如果p2退出,它如何允许p1接收SIGPIPE?