Closed
Description
Home Assistant release (hass --version
):
0.36.1
Python release (python3 --version
):
3.4.3
Component/platform:
sensor:
- platform: systemmonitor
Description of problem:
When tracking the state of some processes, psutil reads in all processes and then filters them.
This results in processes sometimes being stopped before their process files have been read, resulting in an error (see traceback below).
Expected:
It's ok that some processes have been stopped while updating, handling the error would be nicer though.
Problem-relevant configuration.yaml
entries and steps to reproduce:
sensor:
- platform: systemmonitor
resources:
- type: process
arg: deluged
- type: process
arg: deluge-web
Traceback (if applicable):
17-01-27 01:34:54 homeassistant.core: Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/PlexMediaServer/hass/lib/python3.4/site-packages/psutil/_pslinux.py", line 1084, in wrapper
return fun(self, *args, **kwargs)
File "/PlexMediaServer/hass/lib/python3.4/site-packages/psutil/_pslinux.py", line 1157, in name
name = self._parse_stat_file()[0]
File "/PlexMediaServer/hass/lib/python3.4/site-packages/psutil/_common.py", line 293, in wrapper
return fun(self)
File "/PlexMediaServer/hass/lib/python3.4/site-packages/psutil/_pslinux.py", line 1119, in _parse_stat_file
with open_binary("%s/%s/stat" % (self._procfs_path, self.pid)) as f:
File "/PlexMediaServer/hass/lib/python3.4/site-packages/psutil/_pslinux.py", line 181, in open_binary
return open(fname, "rb", **kwargs)
FileNotFoundError: [Errno 2] No such file or directory: '/proc/14214/stat'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.4/asyncio/tasks.py", line 234, in _step
result = coro.throw(exc)
File "/PlexMediaServer/hass/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 387, in _update_entity_states
yield from update_coro
File "/PlexMediaServer/hass/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 216, in async_update_ha_state
yield from self.hass.loop.run_in_executor(None, self.update)
File "/usr/lib/python3.4/asyncio/futures.py", line 386, in __iter__
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.4/asyncio/tasks.py", line 287, in _wakeup
value = future.result()
File "/usr/lib/python3.4/asyncio/futures.py", line 275, in result
raise self._exception
File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
result = self.fn(*self.args, **self.kwargs)
File "/PlexMediaServer/hass/lib/python3.4/site-packages/homeassistant/components/sensor/systemmonitor.py", line 137, in update
if any(self.argument in l.name() for l in psutil.process_iter()):
File "/PlexMediaServer/hass/lib/python3.4/site-packages/homeassistant/components/sensor/systemmonitor.py", line 137, in <genexpr>
if any(self.argument in l.name() for l in psutil.process_iter()):
File "/PlexMediaServer/hass/lib/python3.4/site-packages/psutil/__init__.py", line 634, in name
name = self._proc.name()
File "/PlexMediaServer/hass/lib/python3.4/site-packages/psutil/_pslinux.py", line 1090, in wrapper
raise NoSuchProcess(self.pid, self._name)
psutil.NoSuchProcess: psutil.NoSuchProcess process no longer exists (pid=14214)
Additional info:
I'm not sure if it's helpful, but I use it to track 4 different processes, perhaps this causes the filtering to be slow.