mirror of
https://github.com/python/cpython.git
synced 2025-11-11 14:44:57 +00:00
issue7678 - Properly document how to replace a shell pipeline so that SIGPIPE
happens when the end exits before the beginning.
This commit is contained in:
parent
738236dbd6
commit
e09d2f1614
1 changed files with 3 additions and 0 deletions
|
|
@ -519,8 +519,11 @@ Replacing shell pipeline
|
||||||
==>
|
==>
|
||||||
p1 = Popen(["dmesg"], stdout=PIPE)
|
p1 = Popen(["dmesg"], stdout=PIPE)
|
||||||
p2 = Popen(["grep", "hda"], stdin=p1.stdout, 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]
|
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`
|
Replacing :func:`os.system`
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue