Python - SIGPIPE handled bug
Dieter Maurer
dieter at handshake.de
Sun Jan 23 05:10:43 EST 2000
Hallo Randall
Randall Hopper <aa8vb at yahoo.com> writes on Fri, 21 Jan 2000 16:29:25 -0500:
> > python -c "for i in xrange(1000): print 'Some output'" | head -2
> Some output
> Some output
> Traceback (innermost last):
> File "<string>", line 1, in ?
> IOError: [Errno 32] Broken pipe
> ---------------------------------------------------------------------------
>
> python getting a SIGPIPE is appropriate behavior. "Whether" it gets a
> SIGPIPE is up to the shell, in UNIX:
It seems, that in your case Python does not get a SIGPIPE but
the "write" returns "-1" and "errno==EPIPE".
According to POSIX, this is the behaviour, if SIGPIPE is not handled
by the default action:
EPIPE fd is connected to a pipe or socket whose reading
end is closed. When this happens the writing proÂ
cess will receive a SIGPIPE signal; if it catches,
blocks or ignores this the error EPIPE is returned.
The SIGPIPE handling under Python 1.5.2/Linux 2/Bash seems to be
to ignore the signal (possibly inherited from the bash!).
If you do not like this, use:
import signal
signal.signal(signal.SIGPIPE,signal.SIG_DFL)
Dieter
More information about the Python-list
mailing list