Skip to content

Fix BrokenPipeError crash when pip output is piped#13881

Closed
Bahtya wants to merge 1 commit intopypa:mainfrom
Bahtya:fix-broken-pipe
Closed

Fix BrokenPipeError crash when pip output is piped#13881
Bahtya wants to merge 1 commit intopypa:mainfrom
Bahtya:fix-broken-pipe

Conversation

@Bahtya
Copy link
Copy Markdown

@Bahtya Bahtya commented Apr 4, 2026

Problem

When pip's output is piped to a command that exits early, pip crashes with an uncaught BrokenPipeError:

pip show pip 2>&1 | head -1
# BrokenPipeError: [Errno 32] Broken pipe

Fix

Catch BrokenPipeError explicitly before BaseException and exit cleanly.

Closing in favor of #13878 which was opened earlier and addresses the same issue.

When pip output is piped to a process that exits early (e.g.
`pip show pip | head -1`), Python raises BrokenPipeError. This
was not caught explicitly, causing it to fall through to the
BaseException handler which logs a verbose traceback.

Fix by catching BrokenPipeError before BaseException and exiting
cleanly, following Python's SIGPIPE convention (PEP 389).

Closes #13877
@notatallshaw
Copy link
Copy Markdown
Member

There is already an almost identical PR: https://github.com/pypa/pip/pull/13878/changes

@Bahtya Bahtya closed this Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants