From bf73613b328371b021fe96805282f7417bf33ed3 Mon Sep 17 00:00:00 2001 From: Pranav Lawate Date: Sat, 27 Sep 2025 14:08:57 +0530 Subject: [PATCH] fix: handle SIGPIPE gracefully when output is piped to head/less Fixes BrokenPipeError that occurs when radon output is piped to commands that truncate output (head, less, etc.). This is a common workflow issue that prevents radon from being used in shell pipelines. - Add signal.signal(signal.SIGPIPE, signal.SIG_DFL) to CLI initialization - Enables clean exit when pipe consumer terminates early - No impact on normal output behavior - Follows standard Unix pipe handling conventions Resolves: Broken pipe errors in terminal workflows Tested: All radon commands (cc, raw, mi, hal) work correctly with pipes --- radon/cli/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/radon/cli/__init__.py b/radon/cli/__init__.py index 3af5138..24d2046 100644 --- a/radon/cli/__init__.py +++ b/radon/cli/__init__.py @@ -2,9 +2,14 @@ import inspect import os +import signal import sys from contextlib import contextmanager +# Handle broken pipe gracefully when output is piped to head, less, etc. +# This prevents BrokenPipeError when radon output is truncated by pipe consumers +signal.signal(signal.SIGPIPE, signal.SIG_DFL) + from mando import Program try: # Python 3.11+