I have a GUI program (Python + Qt) coded for my Raspberry Pi. In order to start the program after startup, I have added the following line:
.config/lxsession/LXDE-pi/autostart. This works as intended and starts the program after booting up as well as restarts the program when it occasionally crashes.
The problem is, I have a button in the GUI which should turn the Raspberry Pi off when I want to shut it down. For that, upon pressing this button, my code runs
gpio.cleanup() and then
call("sudo shutdown -P now", shell=True). At this point, in about 4/5 cases the Raspberry Pi successfully shuts down and all is good.
In approximately 1/5 cases though, my GUI program manages to restart before the Raspberry Pi shuts down, preventing the shutdown from happening. How should I fix this?
(I am open to a different way of auto-(re) starting, different way of shutting down or any other solutions. Thank you for your time.)