check if thread is running
-
Hey,
What is best practice for a watchdog in a multithreading system?
So if one thread has an unhandled exeption, restart that thread? -
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
foo()def thread1(): while True: try: #run some code foo() except: #handle all potential errorsIf anyone has a better solution I'm interested as well!
-
@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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login