小编Tam*_*iar的帖子

更换Shell管道

在子进程模块的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?

python python-2.7

9
推荐指数
1
解决办法
364
查看次数

标签 统计

python ×1

python-2.7 ×1