From ac16da4bf74fcde1e4e3f8cec62c140129f6469d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 30 Apr 2019 18:17:15 +0200 Subject: [PATCH] UnixConsole: raise EOFError in case input_fd is not a TTY This is required for when the UnixConsole instance was created with stdin being a terminal, but then later not so anymore. E.g. having used pdbpp before pytest captures output, and then having a set_trace where pytest is capturing output, but the debugging plugin (which suspends capturing) is not active yet (pytest_load_initial_conftests). This will result in pdb raising `BdbQuit` then "correctly". --- pyrepl/reader.py | 2 +- pyrepl/unix_console.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pyrepl/reader.py b/pyrepl/reader.py index 587e3b1..f9869e4 100644 --- a/pyrepl/reader.py +++ b/pyrepl/reader.py @@ -478,8 +478,8 @@ def prepare(self): """Get ready to run. Call restore when finished. You must not write to the console in between the calls to prepare and restore.""" + self.console.prepare() try: - self.console.prepare() self.arg = None self.screeninfo = [] self.finished = 0 diff --git a/pyrepl/unix_console.py b/pyrepl/unix_console.py index a7e311f..452a8a0 100644 --- a/pyrepl/unix_console.py +++ b/pyrepl/unix_console.py @@ -354,7 +354,11 @@ def move_cursor(self, x, y): def prepare(self): # per-readline preparations: - self.__svtermstate = tcgetattr(self.input_fd) + try: + self.__svtermstate = tcgetattr(self.input_fd) + except termios.error: # (25, 'Inappropriate ioctl for device') + # assert not os.fdopen(self.input_fd).isatty() + raise EOFError raw = self.__svtermstate.copy() raw.iflag |= termios.ICRNL raw.iflag &= ~(termios.BRKINT | termios.INPCK |