From 4d989c2570de9af859c09102654c18dd99a21cd4 Mon Sep 17 00:00:00 2001 From: Chris Liechti Date: Mon, 24 Aug 2015 00:24:49 +0200 Subject: miniterm: save original console settings only once --- serial/tools/miniterm.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/serial/tools/miniterm.py b/serial/tools/miniterm.py index d21c8ca..a88e23f 100644 --- a/serial/tools/miniterm.py +++ b/serial/tools/miniterm.py @@ -94,13 +94,12 @@ elif os.name == 'posix': def __init__(self): super(Console, self).__init__() self.fd = sys.stdin.fileno() - self.old = None + self.old = termios.tcgetattr(self.fd) atexit.register(self.cleanup) if sys.version_info < (3, 0): sys.stdin = codecs.getreader(sys.stdin.encoding)(sys.stdin) def setup(self): - self.old = termios.tcgetattr(self.fd) new = termios.tcgetattr(self.fd) new[3] = new[3] & ~termios.ICANON & ~termios.ECHO & ~termios.ISIG new[6][termios.VMIN] = 1 @@ -113,8 +112,7 @@ elif os.name == 'posix': #~ return c def cleanup(self): - if self.old is not None: - termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old) + termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old) else: raise NotImplementedError("Sorry no implementation for your platform (%s) available." % sys.platform) -- cgit v1.2.1