Skip to content

Don't print BrokenPipeError when stdout is closed early - #1098

Open
itzzdev09 wants to merge 1 commit into
getslash:developfrom
itzzdev09:broken-pipe-on-closed-stdout
Open

itzzdev09 wants to merge 1 commit into
getslash:developfrom
itzzdev09:broken-pipe-on-closed-stdout

Conversation

@itzzdev09

Copy link
Copy Markdown

Fixes #967.

slash list-config | head -2 (and slash list tests | head) printed this after the output, and exited with status 120:

Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe

main_entry_point now flushes stdout inside its try, so the closed pipe is raised there, catches BrokenPipeError, points stdout at os.devnull (so the flush at interpreter exit has nothing to fail on), and exits with status 1. This is the pattern from the Python docs for the same problem.

I checked it on Linux (python:3.12-slim in Docker) by running slash list-config | head -2 before and after the change: before, the message above and exit status 120; after, just the two lines and exit status 1. Added test_slash_list_config_closed_stdout_pipe, which starts list-config with its stdout pipe already closed and checks that stderr has no BrokenPipeError; it fails without the change and passes with it (3 passed in tests/test_list_config.py). The test is skipped on Windows like the other POSIX-only tests; I did not run the rest of the suite.

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.

BrokenPipeError raised when redirect list commands' output to head

1 participant