【发布时间】:2015-01-06 10:07:41
【问题描述】:
在 Python 2.7 的 subprocess 模块文档中,我找到了以下 sn-ps:
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]
来源: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?
【问题讨论】:
标签: python python-2.7