diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-10-01 19:06:56 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-10-01 19:08:36 +0300 |
commit | bb7d3d1539e2da12ab6c9ae7e6b96e67005594dd (patch) | |
tree | 7ecbdc3e2eb41ce4a3136c17137f0c349068a196 | |
parent | c8ca5d52b2cd1424e2b19f457d766938396cd520 (diff) | |
download | python-ttystatus-bb7d3d1539e2da12ab6c9ae7e6b96e67005594dd.tar.gz |
Handle lack of /dev/tty
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | ttystatus/tty.py | 25 |
2 files changed, 20 insertions, 11 deletions
@@ -1,6 +1,12 @@ NEWS file for ttystatus ======================= +Version 0.24.1, released 2015-10-01 +--------------------------------- + +* Fix handling the case of the process not having a terminal to talk + to. Reported by Juergen Nickelsen. + Version 0.24, released 2015-09-30 --------------------------------- diff --git a/ttystatus/tty.py b/ttystatus/tty.py index 094cee9..f37b825 100644 --- a/ttystatus/tty.py +++ b/ttystatus/tty.py @@ -53,12 +53,14 @@ class PhysicalTerminal(object): width = 80 - try: - s = struct.pack('HHHH', 0, 0, 0, 0) - x = fcntl.ioctl(self._terminal.fileno(), termios.TIOCGWINSZ, s) - width = struct.unpack('HHHH', x)[1] - except IOError: - pass + if self._terminal is not None: + try: + s = struct.pack('HHHH', 0, 0, 0, 0) + x = fcntl.ioctl( + self._terminal.fileno(), termios.TIOCGWINSZ, s) + width = struct.unpack('HHHH', x)[1] + except IOError: + pass return width @@ -69,8 +71,9 @@ class PhysicalTerminal(object): ''' - try: - self._terminal.write(raw_data) - self._terminal.flush() - except IOError: - pass + if self._terminal is not None: + try: + self._terminal.write(raw_data) + self._terminal.flush() + except IOError: + pass |