mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.13] gh-135329: prevent infinite traceback loop on Ctrl-C for strace (#138974)
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: dura0ok <slpmcf@gmail.com>
Co-authored-by: graymon <greyschwinger@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit b9dbf6acb3)
This commit is contained in:
parent
2b8ff3ca66
commit
35ba6d4035
4 changed files with 172 additions and 3 deletions
|
|
@ -349,7 +349,14 @@ 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.
|
||||
raise
|
||||
|
||||
# In macOS terminal we need to deactivate line wrap via ANSI escape code
|
||||
if self.is_apple_terminal:
|
||||
|
|
@ -381,7 +388,11 @@ 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:
|
||||
raise
|
||||
|
||||
if self.is_apple_terminal:
|
||||
os.write(self.output_fd, b"\033[?7h")
|
||||
|
|
@ -420,6 +431,8 @@ def get_event(self, block: bool = True) -> Event | None:
|
|||
return self.event_queue.get()
|
||||
else:
|
||||
continue
|
||||
elif err.errno == errno.EIO:
|
||||
raise SystemExit(errno.EIO)
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue