check if thread is running
What is best practice for a watchdog in a multithreading system?
So if one thread has an unhandled exeption, restart that thread?
@Gijs Thought of about the same thing. I would just add a short sleep at the end of the loop, so that in case it fails very quickly it doesn't go into a tight loop, especially if the code in the thread is sending anything (over the network or to a device connected via I2C or SPI etc.). Of course it relies on the contents of the function being able to restart a second time.
I'm not sure this is 100% fool proof as I believe there are cases when some conditions will not result in proper exceptions being thrown, so of course using and feeding
WDT(or an external watchdog) may be a good idea as well.
I'd imagine you could do something like this, but there's probably a better solution that I cannot think of right now. Also I'm not sure whether that also handles exceptions that occur inside
def thread1(): while True: try: #run some code foo() except: #handle all potential errors
If anyone has a better solution I'm interested as well!