gpt4 book ai didi

python - 更换 Shell 管道

转载 作者:太空狗 更新时间:2023-10-29 20:25:32 27 4
gpt4 key购买 nike

<分区>

在 subprocess 模块的 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]

来源: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?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com