]> granicus.if.org Git - python/commitdiff
issue7678 - Properly document how to replace a shell pipeline so that SIGPIPE
authorGregory P. Smith <greg@mad-scientist.com>
Sat, 5 Feb 2011 21:47:25 +0000 (21:47 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Sat, 5 Feb 2011 21:47:25 +0000 (21:47 +0000)
happens when the end exits before the beginning.

Doc/library/subprocess.rst

index e08dc8e95ee3a60858eddc7d5843c57bb688b225..bcd38de3e3cb9cf7ed1efaab740d1cd6a61cbdc7 100644 (file)
@@ -519,8 +519,11 @@ Replacing shell pipeline
    ==>
    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.
 
 Replacing :func:`os.system`
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^