🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    How to interrupt urequests if it hangs

    Micropython
    2
    3
    4.3k
    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.
    • O
      ondrej1024
      last edited by

      The urequests.request() method does not implement e timeout parameter (like its big brother). So if there is not response to a certain request, the method will hang forever.

      To work around this I am starting a timer just before the urequests.request() call and stop it directly after it. So if the method does not return within a define time, the timer will fire and I can do something.

      So the question is, when the timer fires, which means urequests.request() is stuck, what can I do to recover? One thing could be to reset the device. But is there a more soft way to do this and continue with the application?

      Thanks, Ondrej

      1 Reply Last reply Reply Quote 0
      • ajb2k3A
        ajb2k3
        last edited by

        Are you using a normal timer or a watchdog timer?
        A watchdog timer will trigger a reboot if something fail to respond for example urequests.request()

        You set the watchdog to run at the beginning and place feed watchdog at the end of the main program loop. If the loop does not complete, feed watchdog doesn't get passed which triggers a reboot.

        UIFlow, so easy an adult can learn it!
        If I don't know it, be patient!
        I've ether not learned it or am too drunk to remember it!
        Author of the WIP UIFlow Handbook!
        M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

        1 Reply Last reply Reply Quote 0
        • O
          ondrej1024
          last edited by

          Yes, watchdog timer could be an idea. The same can be done with a normal timer and calling machine.reset() when it fires.

          However I was wondering if there was a more graceful way of handling this, e.g. interrupting just the hanging urequests.request() method and then continuing with the program without rebooting the whole device.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post