Skip to content

Running python REPL under another program + Ctrl-C results in an exception traceback #135329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cmaloney opened this issue Jun 10, 2025 · 0 comments
Labels
stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@cmaloney
Copy link
Contributor

cmaloney commented Jun 10, 2025

Bug report

Bug description:

Running python REPL under another program (strace ./build/python in my case), then pressing Ctrl-C on Linux results in an infinite stream of exception tracebacks.

Tested on Python 3.13 branch and main

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/build/python/cpython/Lib/_pyrepl/readline.py", line 394, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 742, in readline
    self.prepare()
    ~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/historical_reader.py", line 306, in prepare
    super().prepare()
    ~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 594, in prepare
    self.restore()
    ~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 608, in restore
    self.console.restore()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/unix_console.py", line 371, in restore
    tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/python/cpython/Lib/_pyrepl/fancy_termios.py", line 57, in tcsetattr
    termios.tcsetattr(fd, when, attrs.as_list())
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (5, 'Input/output error')
Traceback (most recent call last):
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 585, in prepare
    self.console.prepare()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/unix_console.py", line 339, in prepare
    tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/python/cpython/Lib/_pyrepl/fancy_termios.py", line 57, in tcsetattr
    termios.tcsetattr(fd, when, attrs.as_list())
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (5, 'Input/output error')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/build/python/cpython/Lib/_pyrepl/readline.py", line 394, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 742, in readline
    self.prepare()
    ~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/historical_reader.py", line 306, in prepare
    super().prepare()
    ~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 594, in prepare
    self.restore()
    ~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 608, in restore
    self.console.restore()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/unix_console.py", line 371, in restore
    tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/python/cpython/Lib/_pyrepl/fancy_termios.py", line 57, in tcsetattr
    termios.tcsetattr(fd, when, attrs.as_list())
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (5, 'Input/output error')
Traceback (most recent call last):
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 585, in prepare
    self.console.prepare()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/unix_console.py", line 339, in prepare
    tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/python/cpython/Lib/_pyrepl/fancy_termios.py", line 57, in tcsetattr
    termios.tcsetattr(fd, when, attrs.as_list())
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (5, 'Input/output error')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/build/python/cpython/Lib/_pyrepl/readline.py", line 394, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 742, in readline
    self.prepare()
    ~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/historical_reader.py", line 306, in prepare
    super().prepare()
    ~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 594, in prepare
    self.restore()
    ~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 608, in restore
    self.console.restore()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/unix_console.py", line 371, in restore
    tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/python/cpython/Lib/_pyrepl/fancy_termios.py", line 57, in tcsetattr
    termios.tcsetattr(fd, when, attrs.as_list())
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (5, 'Input/output error')
Traceback (most recent call last):
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 585, in prepare
    self.console.prepare()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/unix_console.py", line 339, in prepare
    tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/python/cpython/Lib/_pyrepl/fancy_termios.py", line 57, in tcsetattr
    termios.tcsetattr(fd, when, attrs.as_list())
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (5, 'Input/output error')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/build/python/cpython/Lib/_pyrepl/readline.py", line 394, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 742, in readline
    self.prepare()
    ~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/historical_reader.py", line 306, in prepare
    super().prepare()
    ~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 594, in prepare
    self.restore()
    ~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 608, in restore
    self.console.restore()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/unix_console.py", line 371, in restore
    tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/python/cpython/Lib/_pyrepl/fancy_termios.py", line 57, in tcsetattr
    termios.tcsetattr(fd, when, attrs.as_list())
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (5, 'Input/output error')
Traceback (most recent call last):
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 585, in prepare
    self.console.prepare()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/unix_console.py", line 339, in prepare
    tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/python/cpython/Lib/_pyrepl/fancy_termios.py", line 57, in tcsetattr
    termios.tcsetattr(fd, when, attrs.as_list())
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (5, 'Input/output error')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/build/python/cpython/Lib/_pyrepl/readline.py", line 394, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 742, in readline
    self.prepare()
    ~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/historical_reader.py", line 306, in prepare
    super().prepare()
    ~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 594, in prepare
    self.restore()
    ~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 608, in restore
    self.console.restore()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/unix_console.py", line 371, in restore
    tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/python/cpython/Lib/_pyrepl/fancy_termios.py", line 57, in tcsetattr
    termios.tcsetattr(fd, when, attrs.as_list())
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (5, 'Input/output error')
Traceback (most recent call last):
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 585, in prepare
    self.console.prepare()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/unix_console.py", line 339, in prepare
    tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/python/cpython/Lib/_pyrepl/fancy_termios.py", line 57, in tcsetattr
    termios.tcsetattr(fd, when, attrs.as_list())
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (5, 'Input/output error')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/build/python/cpython/Lib/_pyrepl/readline.py", line 394, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 742, in readline
    self.prepare()
    ~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/historical_reader.py", line 306, in prepare
    super().prepare()
    ~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 594, in prepare
    self.restore()
    ~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 608, in restore
    self.console.restore()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/unix_console.py", line 371, in restore
    tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/python/cpython/Lib/_pyrepl/fancy_termios.py", line 57, in tcsetattr
    termios.tcsetattr(fd, when, attrs.as_list())
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (5, 'Input/output error')
Traceback (most recent call last):
  File "/build/python/cpython/Lib/_pyrepl/reader.py", line 585, in prepare
    self.console.prepare()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/build/python/cpython/Lib/_pyrepl/unix_console.py", line 339, in prepare
    tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/python/cpython/Lib/_pyrepl/fancy_termios.py", line 57, in tcsetattr
    termios.tcsetattr(fd, when, attrs.as_list())
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
termios.error: (5, 'Input/output error')

CPython versions tested on:

3.13

Operating systems tested on:

Linux

@cmaloney cmaloney added the type-bug An unexpected behavior, bug, or error label Jun 10, 2025
@picnixz picnixz added stdlib Python modules in the Lib dir topic-repl Related to the interactive shell labels Jun 10, 2025
dura0ok added a commit to dura0ok/cpython that referenced this issue Jun 10, 2025
…rnal 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants