From 6c0f4c35f6e6ea8c2993c6582f2f983bc9c4c5ad Mon Sep 17 00:00:00 2001 From: Tom Matheussen Date: Sat, 23 Sep 2017 18:31:25 +0200 Subject: [PATCH] Catch no longer existing process in systemmonitor (#9535) * Catch no longer existing process in systemmonitor * Update log message * Again line length --- homeassistant/components/sensor/systemmonitor.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/sensor/systemmonitor.py b/homeassistant/components/sensor/systemmonitor.py index 1a8d67de93e..5fe1518a315 100755 --- a/homeassistant/components/sensor/systemmonitor.py +++ b/homeassistant/components/sensor/systemmonitor.py @@ -140,10 +140,16 @@ class SystemMonitorSensor(Entity): elif self.type == 'processor_use': self._state = round(psutil.cpu_percent(interval=None)) elif self.type == 'process': - if any(self.argument in l.name() for l in psutil.process_iter()): - self._state = STATE_ON - else: - self._state = STATE_OFF + for proc in psutil.process_iter(): + try: + if self.argument == proc.name(): + self._state = STATE_ON + return + except psutil.NoSuchProcess as err: + _LOGGER.warning( + "Failed to load process with id: %s, old name: %s", + err.pid, err.name) + self._state = STATE_OFF elif self.type == 'network_out' or self.type == 'network_in': counters = psutil.net_io_counters(pernic=True) if self.argument in counters: