Skip to content

Commit b9f8ca9

Browse files
committed
more defensive
1 parent f6b777a commit b9f8ca9

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pyrepl/reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ def prepare(self):
478478
"""Get ready to run. Call restore when finished. You must not
479479
write to the console in between the calls to prepare and
480480
restore."""
481-
self.console.prepare()
482481
try:
482+
self.console.prepare()
483483
self.arg = None
484484
self.screeninfo = []
485485
self.finished = 0

pyrepl/unix_console.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ def prepare(self):
359359
except termios.error: # (25, 'Inappropriate ioctl for device')
360360
# assert not os.fdopen(self.input_fd).isatty()
361361
raise EOFError
362+
self._prepared = True
362363
raw = self.__svtermstate.copy()
363364
raw.iflag |= termios.ICRNL
364365
raw.iflag &= ~(termios.BRKINT | termios.INPCK |
@@ -391,6 +392,9 @@ def prepare(self):
391392
pass
392393

393394
def restore(self):
395+
if not hasattr(self, '_prepared'):
396+
return
397+
del self._prepared
394398
self.__maybe_write_code(self._rmkx)
395399
self.flushoutput()
396400
tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)

0 commit comments

Comments
 (0)