Page 1 of 1

can't stop Timer in Thonny

Posted: Wed Jan 12, 2022 5:57 am
by y1ngkhun
I just coding micropython useing Timer function
Try to Stop/Restart backend (Ctrl+F2) then Interrupt execution (Ctrl+C)
but its look like Timer function not stop running
device can't save or do anything

IDE warning
"Device is Busy - can't perform this action now. Please wait or cancel current work and try again!

Thanks

Re: can't stop Timer in Thonny

Posted: Wed Jan 12, 2022 5:34 pm
by scruss
Which board are you using?

There's a problem with MicroPython 1.17 on Raspberry Pi Pico/RP2040 that makes MicroPython scripts hard to stop sometimes.

Re: can't stop Timer in Thonny

Posted: Thu Jan 13, 2022 7:28 am
by y1ngkhun
I used esp32, micropython 1.17, thonny 3.3.13

Re: can't stop Timer in Thonny

Posted: Sat Jan 15, 2022 8:12 am
by aivarannamaa
I thought Ctrl+C is only supposed to interrupt the main thread, not timers nor disable the irq-s. Can someone confirm the opposite?

Re: can't stop Timer in Thonny

Posted: Sat Jan 15, 2022 12:17 pm
by Roberthh
That‘s indeed the case. CTRL-C raises a Keyboard interrupt exception, unless that is disabled. CTRL-D causes a reboot, which should stop timers and other activities, like PWM.

Re: can't stop Timer in Thonny

Posted: Sun Jan 16, 2022 8:21 am
by y1ngkhun
Roberthh wrote:
Sat Jan 15, 2022 12:17 pm
That‘s indeed the case. CTRL-C raises a Keyboard interrupt exception, unless that is disabled. CTRL-D causes a reboot, which should stop timers and other activities, like PWM.
CTRL-D for reboot then my esp32 go back to main.py timers loop again :(

Re: can't stop Timer in Thonny

Posted: Sun Jan 16, 2022 10:33 am
by aivarannamaa
If you want to stop your timers with Ctrl+C, then wrap your code into a try and explicitly stop the timers (and disable irq-s) in the finally block.

Also, if you use threads, I would suggest joining them before returning to REPL, so that Thonny can execute its management commands without being confused by unexpected output. With some ports, a background thread interferes with using REPL even if it doesn't print anything (https://github.com/micropython/micropython/issues/6899).

Re: can't stop Timer in Thonny

Posted: Sat Aug 20, 2022 5:27 pm
by Jibun no kage
Example of how to disable irq-s?