Python 2.2.1: os.popen() bug?

Donn Cave donn at u.washington.edu
Wed May 29 12:34:31 EDT 2002


Quoth Michael Hudson <mwh at python.net>:
| "Donn Cave" <donn at u.washington.edu> writes:
|
| > If it had been for some reason writing to output, it would have
| > gotten a SIGPIPE.
|
| Not sure about context, but Python ignores SIGPIPEs by default.  So
| this is probably not much use.

Oops, thanks for catching that.  I see a command process forked
from python by popen() does inherit that behavior.

So I guess it's just a bad idea to use popen(cmd, 'r') unless cmd
can be relied on to terminate on its own.  Unlike C popen(), the
cmd process from a Python popen() will continue to write to its
output unit forever, and python will wait forever, until someone
aborts it externally.  It won't be a common problem, only applies
to applications that talk forever, like "ping" or "tail -f".
In a case like that, one would want to defeat this questionable
feature prior to popen(), e.g.,

   signal.signal(signal.SIGPIPE, signal.SIG_DFL)

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list