From b26ba73515ee02a9c082035e885945b71b57e0a9 Mon Sep 17 00:00:00 2001 From: Adam Binford Date: Sun, 21 Dec 2025 16:31:36 -0500 Subject: [PATCH] Wrap cli functions in catching broken pipes --- python/hdfs_native/cli.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/python/hdfs_native/cli.py b/python/hdfs_native/cli.py index d2dcd95..29fe9a8 100644 --- a/python/hdfs_native/cli.py +++ b/python/hdfs_native/cli.py @@ -1,5 +1,4 @@ # PYTHON_ARGCOMPLETE_OK - import functools import glob import os @@ -1391,7 +1390,15 @@ def show_help(args: Namespace): autocomplete(parser) args = parser.parse_args(in_args) - args.func(args) + + # Catch broken pipes in case the output is being piped to a command that exits early + try: + args.func(args) + except BrokenPipeError: + # Python flushes standard streams on exit; redirect remaining output + # to devnull to avoid another BrokenPipeError at shutdown + devnull = os.open(os.devnull, os.O_WRONLY) + os.dup2(devnull, sys.stdout.fileno()) if __name__ == "__main__":