So over the last couple of years I’ve built a couple of devices that run “eternally” using python and a while True loop. Think of things like lights that change colour depending on a third party API (like cheerlights) or nightlights for my kids that change colour depending on the time of day.
With all of these scripts I’ve noticed that at some point, eventually they will lock up. Not sure if it’s due to lack of memory (often using a Pi Zero) or some error in the code (I’ve found for example that sometimes the Cheerlights API will die for a bit and I haven’t figured out how to handle API failures well in Python yet, mostly because I’m a dirty dirty hacker).
Anyways… I was thinking, would a script that runs once and exits cleanly being fired at intervals by cron be more reliable over a longer period of time than something the while True approach above? Are there any downsides to this approach?
(I’m primarily interested because I’ve just ordered a Phat Stack and some pHats for an upcoming project that will operate multiple pHats and I was thinking it may be easier to just fire multiple scripts via Cron than having to jam it all into a single script that has the potential to fail in many different types of ways).