Skip to content

Commit

Permalink
UnixConsole: raise EOFError in case input_fd is not a TTY
Browse files Browse the repository at this point in the history
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
(`pdb.set_trace()`), and then continuing (`c`).
pytest is capturing output by now then, but the debugging plugin (which
suspends capturing) might not be active yet (pytest_load_initial_conftests).

This patch makes it raise `BdbQuit` then "correctly".
  • Loading branch information
blueyed committed Aug 15, 2019
1 parent b3138ab commit b32f9a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion pyrepl/unix_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down

0 comments on commit b32f9a3

Please sign in to comment.