Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions Lib/_pyrepl/unix_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,15 @@ def prepare(self):
raw.lflag |= termios.ISIG
raw.cc[termios.VMIN] = 1
raw.cc[termios.VTIME] = 0
tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
try:
tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
except termios.error as e:
if e.args[0] != errno.EIO:
# gh-135329
# When running under external programs (like strace),
# tcsetattr may fail with EIO. We can safely ignore this
# and continue with default terminal settings.
Comment thread
yihong0618 marked this conversation as resolved.
Outdated
raise

# In macOS terminal we need to deactivate line wrap via ANSI escape code
if platform.system() == "Darwin" and os.getenv("TERM_PROGRAM") == "Apple_Terminal":
Expand Down Expand Up @@ -368,7 +376,15 @@ def restore(self):
self.__disable_bracketed_paste()
self.__maybe_write_code(self._rmkx)
self.flushoutput()
tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
try:
tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
except termios.error as e:
if e.args[0] != errno.EIO:
# gh-135329
# When running under external programs (like strace),
# tcsetattr may fail with EIO. We can safely ignore this
# and continue with default terminal settings.
Comment thread
yihong0618 marked this conversation as resolved.
Outdated
raise

Comment thread
yihong0618 marked this conversation as resolved.
if platform.system() == "Darwin" and os.getenv("TERM_PROGRAM") == "Apple_Terminal":
os.write(self.output_fd, b"\033[?7h")
Expand Down Expand Up @@ -407,6 +423,13 @@ def get_event(self, block: bool = True) -> Event | None:
return self.event_queue.get()
else:
continue
elif err.errno == errno.EIO:
# gh-135329
# When running under external programs (like strace),
# os.read may fail with EIO. In this case, we should
# exit gracefully to avoid infinite error loops.
Comment thread
yihong0618 marked this conversation as resolved.
Outdated
import sys
sys.exit(errno.EIO)
Comment thread
yihong0618 marked this conversation as resolved.
Outdated
else:
raise
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent infinite traceback loop when sending CTRL^C to Python through ``strace``.
Loading