Continuously running Python code for Pimoroni buttonshim on Raspberry Pi causing freezing

I am using a Raspberry Pi 3B+ to display a website/websites on a screen, and recently attached a Pimoroni Button-Shim.

Since writing some Python code (below) I have had the buttons working, but the Raspberry Pi seems to freeze after about 18 hours. I’ve never been around to see it happen, but on returning it has now been frozen three times.

It never did this before I wrote this code, and assume it probably has something to do with poorly written code, rather than the soldering itself.

I have a bit of experience with Python, but never with continuously running programs, and handlers are a new concept for me.

The code is Python 3, using the library provided by Pimoroni, and starts via LXDE-pi/autostart.

If you have any idea on how to help that would be greatly appreciated, I’ve had a bit of a google, but don’t really know any resources or what to type in to find a solution.

It works immediately on hard reboot, and I’m not really sure where to go next.

#!usr/bin/python3
import buttonshim
from time import sleep
import os

sleep(10)
os.system('chromium-browser --noerrdialogs --incognito --kiosk  url1')
buttonshim.set_pixel(221,36,33)

@buttonshim.on_press(buttonshim.BUTTON_A)
def handler(button, pressed):
    os.system('pkill chromium-browser')
    os.system('chromium-browser --noerrdialogs --incognito --kiosk https://www.nytimes.com')
    buttonshim.set_pixel(33, 106, 224)

@buttonshim.on_press(buttonshim.BUTTON_B)
def handler(button, pressed):
    os.system('pkill chromium-browser')
    os.system('chromium-browser --noerrdialogs --incognito --kiosk url1')
    buttonshim.set_pixel(0xFF, 0x00, 0xFF)


@buttonshim.on_press(buttonshim.BUTTON_C)
def handler(button, pressed):
    os.system('vcgencmd display_power 0')

@buttonshim.on_press(buttonshim.BUTTON_D)
def handler(button, pressed):
    os.system('vcgencmd display_power 1')

while True:
    sleep(10)

The code works as expected at the start, but eventually doesn’t.

Is the Pi freezing completely- IE: you cannot SSH in or interact with it in any way? Or is it just the code that’s failing?

Does the Pi still freeze (assuming it’s the Pi freezing) without the code running?