File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 1313# startup of the CLI tool.
1414from __future__ import annotations
1515import sys
16+ import os
17+ from os import path
1618import argparse
1719from typing import List , Iterable , Tuple
18- from os import path
1920from textwrap import dedent
2021from shutil import get_terminal_size
2122import posixpath
@@ -344,4 +345,13 @@ def _on_command_integration(args: argparse.Namespace):
344345
345346
346347if __name__ == '__main__' :
347- sys .exit (main ())
348+ # Prevent "[Errno 32] Broken pipe" error.
349+ # https://docs.python.org/3/library/signal.html#note-on-sigpipe
350+ try :
351+ sys .exit (main ())
352+ except BrokenPipeError :
353+ # Python flushes standard streams on exit; redirect remaining output
354+ # to devnull to avoid another BrokenPipeError at shutdown.
355+ devnull = os .open (os .devnull , os .O_WRONLY )
356+ os .dup2 (devnull , sys .stdout .fileno ())
357+ sys .exit (1 ) # Python exits with error code 1 on EPIPE
You can’t perform that action at this time.
0 commit comments