Catch no longer existing process in systemmonitor (#9535)

* Catch no longer existing process in systemmonitor

* Update log message

* Again line length
pull/9555/head
Tom Matheussen 2017-09-23 18:31:25 +02:00 committed by Fabian Affolter
parent 08b0629eca
commit 6c0f4c35f6
1 changed files with 10 additions and 4 deletions

View File

@ -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: