Re: IOError: [Errno 32] Broken pipe

From: Christopher T King (squirrel_at_WPI.EDU)
Date: 06/29/04

Date: Mon, 28 Jun 2004 18:47:48 -0400

On 28 Jun 2004, Jay Donnell wrote:

> I'm working on a simple script to manipulate csv files. Right now it
> just prints the first field of the file for each line. Everything
> works fine, but if I use 'head' or 'more' and quit while in more then
> I get
> IOError: [Errno 32] Broken pipe
> Anyone know why this is happening?

That's normal, at least with Unix. When the program on the receiving end
of a pipe decides to close its end for some reason, Unix sends the signal
'SIGPIPE' to the sending end. Python catches this and turns it into an
IOError exception. The only way around this (that I can think of) is to
catch the exception and exit the program gracefully. If you try to send
more data, you will get more IOErrors, since your program has nowhere left
to send data.