Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    check if thread is running

    Scheduled Pinned Locked Moved MicroPython
    watchdogthreading
    3 Posts 3 Posters 44 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T Offline
      tttadam
      last edited by

      Hey,
      What is best practice for a watchdog in a multithreading system?
      So if one thread has an unhandled exeption, restart that thread?

      1 Reply Last reply Reply Quote 0
      • G Offline
        Gijs
        last edited by

        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 errors 
        

        If anyone has a better solution I'm interested as well!

        J 1 Reply Last reply Reply Quote 0
        • J Offline
          jcaron @Gijs
          last edited by

          @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.

          1 Reply Last reply Reply Quote 1

          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
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom