Skip to content

Commit 4eb8fa5

Browse files
committed
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.
1 parent 0f866cb commit 4eb8fa5

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Lib/_pyrepl/reader.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
from . import commands, console, input
3131
from .utils import wlen, unbracket, disp_str, gen_colors, THEME
3232
from .trace import trace
33+
import termios
34+
import errno
3335

3436

3537
# types
@@ -590,6 +592,10 @@ def prepare(self) -> None:
590592
self.dirty = True
591593
self.last_command = None
592594
self.calc_screen()
595+
except termios.error as e:
596+
if e.args[0] == errno.EIO:
597+
return
598+
raise
593599
except BaseException:
594600
self.restore()
595601
raise

0 commit comments

Comments
 (0)