469,645 Members | 1,150 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

ignoring SIGPIPE in a python script?


I have a python script that sometimes gets a SIGPIPE signal, and errors
out. And I want it to just terminate as though it had hit EOF.

I'm running:

signal.signal(signal.SIGPIPE,signal.SIG_IGN)

....in the main function, but the script is still erroring out on sigpipe
when the consumer to its producer terminates early.

Am I going to have to code in a handful of exceptions, and then
conditionalize what happens in those exception handlers, to get the
desired behavior?

ISTR hearing that although bash notifies one of SIGPIPE errors, tcsh
generally silently ignores them. From this, I conclude that it might be
reasonable for my script to ignore SIGPIPE.

Thanks!

Jul 19 '05 #1
1 3904
In article <pa****************************@dcs.nac.uci.edu> ,
Dan Stromberg <st******@dcs.nac.uci.edu> wrote:
I have a python script that sometimes gets a SIGPIPE signal, and errors
out. And I want it to just terminate as though it had hit EOF.

I'm running:

signal.signal(signal.SIGPIPE,signal.SIG_IGN)

...in the main function, but the script is still erroring out on sigpipe
when the consumer to its producer terminates early.

Am I going to have to code in a handful of exceptions, and then
conditionalize what happens in those exception handlers, to get the
desired behavior?

ISTR hearing that although bash notifies one of SIGPIPE errors, tcsh
generally silently ignores them. From this, I conclude that it might be
reasonable for my script to ignore SIGPIPE.


This is a little idiosyncracy of Python's. You can restore
the default signal handler,
signal.signal(signal.SIGPIPE, signal.SIG_DFL)

and it will behave like a normal UNIX application. These other
applications aren't precisely ignoring SIGPIPE, though. If you
think about what that would look like, I guess it would mean they
would continue to write output, since it's truly a rare application
that checks its output (especially since it's usually buffered.)
The SIGPIPE signal just aborts the program. Not really very
much like EOF at all.

You could install your own handler, but it would probably make
about as much sense to just trap the exception.

Donn Cave, do**@u.washington.edu
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Erik Johnson | last post: by
2 posts views Thread by DeepBleu | last post: by
52 posts views Thread by Olivier Scalbert | last post: by
4 posts views Thread by Tom Purl | last post: by
reply views Thread by Jack Orenstein | last post: by
17 posts views Thread by Paul Rubin | last post: by
6 posts views Thread by tatamata | last post: by
reply views Thread by mrafi | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.