python
io_error
ai_generated
partial
BrokenPipeError: [Errno 32] Broken pipe
ID: python/brokenpipeerror
80%Fix Rate
85%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 311 | active | — | — | — |
Root Cause
Writing to a pipe/socket that was closed by the reader. Common: piping Python output to head/grep.
genericWorkarounds
-
90% success For CLI tools, handle SIGPIPE: signal.signal(signal.SIGPIPE, signal.SIG_DFL)
import signal signal.signal(signal.SIGPIPE, signal.SIG_DFL)
Sources: https://docs.python.org/3/library/signal.html#note-on-sigpipe
-
85% success For network code, handle the error gracefully — the client disconnected
try: send_response(data) except BrokenPipeError: logging.info('Client disconnected before response completed')Sources: https://docs.python.org/3/library/exceptions.html#BrokenPipeError
Dead Ends
Common approaches that don't work:
-
Increase buffer size
75% fail
Buffer size doesn't matter — the reader has disconnected
-
Wrap every print in try/except
60% fail
Verbose and error-prone — use signal handling instead
Error Chain
Frequently confused with: