How to interrupt urequests if it hangs
-
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
-
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.
-
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.