Python & EPIPE: Handling Chg Proposal

Donn Cave donn at u.washington.edu
Tue Feb 1 15:42:30 EST 2000
Quoth Randall Hopper <aa8vb at yahoo.com>:
|      The gist of the problem is that any program which writes to stdout or
| stderr really needs to handle EPIPE to avoid tripping python error
| tracebacks, and doing so is non-trivial and obfuscates otherwise-simple
| Python code.
|
| Basically, this is buggy Python code:
|     python -c "for i in xrange(100000): print 'Lots of output'" | head

| PROPOSAL:
|
|     Add an "epipe_error" attribute to the file object.  It would determine
|     whether EPIPE errors from read()/write() calls generate SystemExit
|     or IOError exceptions.
|
| By default EPIPEs received from the stdin/out/err files would generate
| SystemExit exceptions (epipe_error = 0).  All other files would default to
| IOError exceptions (epipe_error = 1).

Is the problem really the exception, or the traceback?  It looks to me
like it's the traceback, and nothing else about the exception is any
problem for you.

What if the top level handler that prints out these tracebacks just
handled this one silently, as it does with SystemExit?  That would
allow programs to catch pipe errors if they want, a job that could
be much more awkward if some pipe errors raise SystemExit instead.

I'm not really sure it's a good idea to exit silently on a pipe error,
anyway, but I think that's how I'd do it.

	Donn Cave, University Computing Services, University of Washington
	donn at u.washington.edu



More information about the Python-list mailing list