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 13
13
# startup of the CLI tool.
14
14
from __future__ import annotations
15
15
import sys
16
+ import os
17
+ from os import path
16
18
import argparse
17
19
from typing import List , Iterable , Tuple
18
- from os import path
19
20
from textwrap import dedent
20
21
from shutil import get_terminal_size
21
22
import posixpath
@@ -344,4 +345,13 @@ def _on_command_integration(args: argparse.Namespace):
344
345
345
346
346
347
if __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