So I have a snips voice assistant and have it configured to lower the volume (via appdaemon) when it starts listening after a hotword is detected. How bad would it be to have a 3/4 second loop or so to do that within an app daemon function? I could try to use a datetime and break it down but appdaemon itself may not respond, say 5 times a second or so. Has anyone tried this?
i know AD is designed around a 1 second loop.
trying to cut that to 3/4 would probably give a lot of unexpected and unwanted behaviour.
but if i remember correct, the looptime will be configurable in the version andrew is working on.
so it might be worth it to wait for AD 3.0 which is completely different in the background.
If you mean that the loop (and thus the thread) would last for 3/4 second, then I think it would be fine.
The limitation on loops is avoid to thread starvation, and, as you can only have one voice command running at a time anyway, you would at most only be blocking one thread.
They are both right
I am looking at the possibility of having the scheduler run at quicker than 1 second ticks, that isn’t in 3.0 but is something I have been thinking about.
But as @gpbenton says - tying up a thread for less than a seconds probably isn’t a big deal as long as you have enough other threads to service incoming events and timers.
The number of threads is really just a measure of how many things AD can do at once - in the vast majority of cases, one thread would probably be enough especially as AD will queue any requests that don;t have a thread available.
Thanks for the help. I have it working now and since this is to service a voice assistant it won’t be doing more than one thing at a time.
It would probably be nicer to start a background thread wither by calling a different class or directly withing this class but the practical upshot is that it works fine.