classification
Title: subprocess doesn\'t handle SIGPIPE
Type: feature request Stage: test needed
Components: Library (Lib) Versions: Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: astrand Nosy List: ajaksu2, astrand, diekhans (3)
Priority: normal Keywords

Created on 2006-12-14 00:21 by diekhans, last changed 2009-03-30 18:02 by ajaksu2.

Files
File name Uploaded Description Edit Remove
subprocbug.py diekhans, 2006-12-14 00:21 demo of issue
Messages (3)
msg54948 - (view) Author: Mark Diekhans (diekhans) Date: 2006-12-14 00:21
subprocess keeps other side of child pipe open, making
use of SIGPIPE to terminate writers in a pipeline
not possible.

This is probably a matter of documentation or
providing a method to link up processes, as 
the parent end of the pipe must remain open
until it is connected to the next process in
the pipeline.

An option to enable sigpipe in child would be
nice.

Simple example attached.
msg54949 - (view) Author: Peter Åstrand (astrand) Date: 2007-01-07 14:01
One easy solution is to simply close the pipe in the parent after starting both processes, before calling p1.wait():

p1.stdout.close()

It's not "perfect", though, p1 will execute a while before recieving SIGPIPE. For a perfect solution, it would be necessary to close the pipe end in the parent after the fork but before the exec in the child. This would require some kind of synchronization. 

Moving to feature request. 
msg84596 - (view) Author: Daniel Diniz (ajaksu2) Date: 2009-03-30 18:02
Confirmed on trunk and py3k.
History
Date User Action Args
2009-03-30 18:02:01ajaksu2setversions: + Python 3.1, Python 2.7
nosy: + ajaksu2

messages: + msg84596

stage: test needed
2006-12-14 00:21:37diekhanscreate