I would like to implement a simple watchdog timer in Python with two use cases:
- Watchdog ensures that a function doesn't execute longer than
x
seconds - Watchdog ensures that certain regularly executed function does indeed execute at least every
y
seconds
How do I do that?
signal.alarm()
sets a timeout for your program, and you can call it in your main loop, and set it to the greater of the two times you are prepared to tolerate:Just publishing my own solution to this:
Usage if you want to make sure function finishes in less than
x
seconds:Usage if you regularly execute something and want to make sure it is executed at least every
y
seconds: