From bb7d3d1539e2da12ab6c9ae7e6b96e67005594dd Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 1 Oct 2015 19:06:56 +0300 Subject: Handle lack of /dev/tty --- NEWS | 6 ++++++ ttystatus/tty.py | 25 ++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index c6f5ddc..1ab3c35 100644 --- a/NEWS +++ b/NEWS @@ -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 -- cgit v1.2.1