The 3rd party embedded linux platform on which I am running micropython does not have a watchdog that I can use so I'm curious if there is some internal watchdog in MP itself or some alternative solution. Basically, if someone accidentally writes an infinite loop in a script is there a way to force MP to shutdown/reset? Alternatively is there a way to invoke MP to only run for a given time limit? In other words start MP and then run this script. Either the script will finish executing as expected or the script is stuck in some loop (or other problem) and MicroPython will shutdown after X seconds?
Appreciate the help!
Watchdog Like Feature
Re: Watchdog Like Feature
You should be able to interrupt MicroPython by just entering Control-C.
Re: Watchdog Like Feature
I agree with that however, I forgot to mention that I don't have console access.
Basically we are running C++ code. Based on logic we may decide that we need to run a script. When a script needs to be run, the C++ the code is built to init MP, run the script and stop MP. However we want to be able to stop a script that may have accidentally be written to be an infinite loop.
Basically we are running C++ code. Based on logic we may decide that we need to run a script. When a script needs to be run, the C++ the code is built to init MP, run the script and stop MP. However we want to be able to stop a script that may have accidentally be written to be an infinite loop.
Re: Watchdog Like Feature
The way that the Control-C handling works is that it winds up calling a pendsv_kbd_intr() https://github.com/micropython/micropyt ... art.c#L914
So you could do the same thing from your code when you want to interrupt the code. When you call it the first time, it tries to interrupt "softly". Calling it a second time will be more forcible about interrupting the code.
https://github.com/micropython/micropyt ... .c#L54-L70
So you could do the same thing from your code when you want to interrupt the code. When you call it the first time, it tries to interrupt "softly". Calling it a second time will be more forcible about interrupting the code.
https://github.com/micropython/micropyt ... .c#L54-L70
Re: Watchdog Like Feature
Thanks for this. That's actually really helpful but I don't think it'll help in the specific use case. Calling that function will only work assuming we know that we are stuck in a loop. In a single threaded system the code itself wouldn't know that it's stuck in a loop, thats why I was hoping there is a way to invoke the interpreter for only a given amount of time. Or allow a script to only run for a given amount of time. Appreciate it
Re: Watchdog Like Feature
You would need to do something like have the MicroPython code setup a timer and then perhaps call micropython.schedule http://docs.micropython.org/en/latest/l ... n.schedule
once the timer expired and have that code raise some type of exception.
WatchDog timers, when they exist.generally reset the processor.
once the timer expired and have that code raise some type of exception.
WatchDog timers, when they exist.generally reset the processor.