Author mathmodave
Recipients amaury.forgeotdarc, astrand, cmiller, dmalcolm, gregory.p.smith, jnoller, jyasskin, mathmodave, mattjohnston, mpitt, naufraghi, r.david.murray, rnk, schmir, timjr
Date 2010-01-14.10:58:58
SpamBayes Score 4.8645e-09
Marked as misclassified No
Message-id <1263466742.71.0.191258467206.issue1068268@psf.upfronthosting.co.za>
In-reply-to
Content
Another instance of a blocking function within subprocess not being protected against EINTR 

Python 2.6.4, subprocess.py, Popen function, line 1115:
data = os.read(errpipe_read, 1048576) # Exceptions limited to 1 MB

If a signal arrives while blocked in this read, the EINTR/OSError is passed up to whatever called subprocess.Popen. Retrying the Popen doesn't help because the child process may already have started but the caller has no way to know this nor does the caller have any control over the child process.

===

In the example code, the first subprocess.Popen starts without issue but while in the second Popen call, p1's SIGCHLD is received by the parent. 
p2 is never set, but the second copy of /bin/date starts running anyway.

The "preexec_fn = lambda : time.sleep(2)" in the second Popen is a little contrived but serves to guarantee that the SIGCHLD will break the Popen for the purposes of the demonstration. I have seen this failure mode when using vanilla Popen calls although you have to be lucky/unlucky to see it.

====

This is in python 2.6.4:
> md5sum subprocess.py
2ac8cefe8301eadce87630b230d6fff2  subprocess.py

====

I expect the fix is equivalent to cmiller's trunk-diff-unified.txt
History
Date User Action Args
2010-01-14 10:59:03mathmodavesetrecipients: + mathmodave, gregory.p.smith, astrand, amaury.forgeotdarc, mattjohnston, mpitt, timjr, jyasskin, schmir, jnoller, naufraghi, r.david.murray, rnk, cmiller, dmalcolm
2010-01-14 10:59:02mathmodavesetmessageid: <1263466742.71.0.191258467206.issue1068268@psf.upfronthosting.co.za>
2010-01-14 10:59:00mathmodavelinkissue1068268 messages
2010-01-14 10:58:59mathmodavecreate