From: Gregory P. Smith Date: Sat, 5 Feb 2011 21:47:25 +0000 (+0000) Subject: issue7678 - Properly document how to replace a shell pipeline so that SIGPIPE X-Git-Tag: v3.2rc3~41 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e09d2f1614e96c98b55692281cf2d2be49e9c881;p=thirdparty%2FPython%2Fcpython.git issue7678 - Properly document how to replace a shell pipeline so that SIGPIPE happens when the end exits before the beginning. --- diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst index e08dc8e95ee3..bcd38de3e3cb 100644 --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -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` ^^^^^^^^^^^^^^^^^^^^^^^^^^^