MQTT scripts - looping or standalone

Anyone have any thoughts on this.

Do you think for raspberry pi based scripts (ie dht sensors and the like), is it better the script is like a service always running and looping, or standalone called via cron.

I can do either, and tend to do the standalone method. But having moved a bunch of scripts to be homie-python based they seem to be set up for looping.

I don’t think there is a “better” answer to something like this. It really ends up being driven by personal preference and working with the constraints and limitations of each approach.

Personally, I ended up putting the looping into the script primarily because I have a single script with plugins that does a lot of things for me so it was more convenient to me to create one script that does it than relying on something like cron.

Keep in mind that cron on Linux cannot run any faster than every minute so if you need a faster polling rate than that you will be forced to put the polling into your script. That is another reason I opted for polling in the script as I need sub-second polling periods to sense changed states on the GPIO pins.