Python3 high CPU Usage

Feel free to send it on discord or to my email nick [at] koston [dot] org. No worries on the additional email.

The py-spys you posted are surprisingly clean. stream is taking a bit of cpu time, but nothing else shows up. Can you try a shorter duration?

cool. consider it done.

Ok, im doing it again. Will send it via email as asked above.
This is an excerpt from HTOP showing the 2 processes.


I am sending each a 10, 20, 30 & 60 seconds. Hope that helps :slight_smile:

Screenshot from PySpy TOP:

Thanks for the py-spys. It looks like t might be related to a camera or stream. Can you try disabling the stream integration?

Hi, second day that load average gets over 1 and the CPU History (from within Home Assistant systemmonitor platform) shows that at 4:08am, I lose that history (ie, flat line). I usually runs at 0.20 load average. Not sure if it’s related. Restarting Home Assistant from ‘Configuration/Server Controls’ solves it.

But to try and find what’s causing this, I followed the instruction you gave to install py-spy in docker (I’m running a hassio in a supervised installation on a Raspberry 4) and get the following :

pi@homeassistant:~ $ sudo docker exec -it homeassistant /bin/bash
bash-5.0# echo 'manylinux1_compatible = True' > /usr/local/lib/python3.8/site-packages/_manylinux.py
bash-5.0# pip install py-spy
ERROR: Could not find a version that satisfies the requirement py-spy (from versions: none)
ERROR: No matching distribution found for py-spy

Running Home Assistant Core 116.0. Don’t know why it doesn’t want to install and I’m no closer at figuring what’s hogging Home Assistant :frowning:

The new monitoring tools are revealing this:

Core CPU

Supervisor CPU

System Monitor CPU

Profiler is not revealing anything amiss. What next?

Hi, where did you get the new system metrics history graph? All I have are bar charts under Supervisor and can’t find what you’re showing anywhere. Thanks

Here, though I slowed them down to 30 second updates:

1 Like

Using ‘cargo’ I was able to install py-spy.

Again today, last entry in the logbook was at 4am and it was a time changed to 4:12am. No other log entry until I restarted Home Assistant.

4:12am is when the recorder is purged. Make sure you are on 0.116.1 or later as 0.116.0 couldn’t recover from invalid data being passed to the recorder.

Its probably something running away in another thread. py-spy is likely needed to find this one.

Oh, then it’s probably not related then. I’ll upgrade.

I managed to install py-spy using the command line in portainer. Did a test run and all went to plan. Just a matter of waiting until it happens again.

EDIT: unfortunately I was still in the home assistant container and not the host system. There does not seem to be a way to do this remotely without previously setting up shared keys. And the issue is still occurring. Looks like my only solution at the moment is a restart every morning.

1 Like

searched for that, but couldnt find, what/where is it?
Can we set that up using Portainer maybe? Using Homeassistant OS (former Hassio) here

edit

o wait just finished this thread and found

grrr, was just starting you how you managed in portainer, only to find now this is not useful at all?

Nope, not useful. Sorry.

Running py-spy in the container is the expected way to use it. You shouldn’t need to access the host system.

Running top in the home assistant container I could not see any outlandish cpu use while the core processor was reported to be 100% but will pass on the py-spy svg soon.

1 Like

It seems to be indeed the generic IP RTSP Camera. Once the stream is opened once, the Python 3 process slowly keeps going up in CPU.

Since I installed 0.106.2, didn’t get any high CPU/Load so for me, this fixed it somehow.