From 4eb8fa58a5fb74f105ce73240b4c7ed34cadfc69 Mon Sep 17 00:00:00 2001 From: Stepan Neretin Date: Wed, 11 Jun 2025 05:13:23 +0700 Subject: [PATCH] gh-135329: prevent infinite traceback loop on Ctrl-C under external programs When running Python REPL under another program (e.g., strace) and pressing Ctrl-C, termios raises `EIO` during terminal state restoration, causing infinite exception tracebacks. This patch catches `termios.error` with `errno.EIO` in `reader.prepare()` to avoid recursive failure loops when restoring console state. --- Lib/_pyrepl/reader.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py index 0ebd9162eca4bb..e1e4c190260190 100644 --- a/Lib/_pyrepl/reader.py +++ b/Lib/_pyrepl/reader.py @@ -30,6 +30,8 @@ from . import commands, console, input from .utils import wlen, unbracket, disp_str, gen_colors, THEME from .trace import trace +import termios +import errno # types @@ -590,6 +592,10 @@ def prepare(self) -> None: self.dirty = True self.last_command = None self.calc_screen() + except termios.error as e: + if e.args[0] == errno.EIO: + return + raise except BaseException: self.restore() raise