From 4b72b7760cd5599a60445ca66a46bb516c592dc8 Mon Sep 17 00:00:00 2001 From: Ben Hsing Date: Fri, 23 May 2025 17:02:50 +0800 Subject: [PATCH 1/2] gh-134568: added handler for BrokenPipeError to logging.StreamHandler.emit --- Lib/logging/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 5c3c44249345f3..aec6bc45b6e8fe 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1155,6 +1155,10 @@ def emit(self, record): self.flush() except RecursionError: # See issue 36272 raise + except BrokenPipeError: + devnull = os.open(os.devnull, os.O_WRONLY) + os.dup2(devnull, sys.stdout.fileno()) + sys.exit(1) except Exception: self.handleError(record) From a080880168cac0585125822e26652ce923db6f5b Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 09:10:03 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2025-05-23-09-09-54.gh-issue-134568.BevBCI.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-05-23-09-09-54.gh-issue-134568.BevBCI.rst diff --git a/Misc/NEWS.d/next/Library/2025-05-23-09-09-54.gh-issue-134568.BevBCI.rst b/Misc/NEWS.d/next/Library/2025-05-23-09-09-54.gh-issue-134568.BevBCI.rst new file mode 100644 index 00000000000000..65d1f816758444 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-05-23-09-09-54.gh-issue-134568.BevBCI.rst @@ -0,0 +1 @@ +:class:`logging.StreamHandler` now handles :exc:`BrokenPipeError` when the output is cut short by piping to the ``head`` utility.