can't stop Timer in Thonny

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
y1ngkhun
Posts: 7
Joined: Thu Jul 08, 2021 7:49 am

can't stop Timer in Thonny

Post by y1ngkhun » Wed Jan 12, 2022 5:57 am

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

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: can't stop Timer in Thonny

Post by scruss » Wed Jan 12, 2022 5:34 pm

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.

y1ngkhun
Posts: 7
Joined: Thu Jul 08, 2021 7:49 am

Re: can't stop Timer in Thonny

Post by y1ngkhun » Thu Jan 13, 2022 7:28 am

I used esp32, micropython 1.17, thonny 3.3.13

User avatar
aivarannamaa
Posts: 171
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

Re: can't stop Timer in Thonny

Post by aivarannamaa » Sat Jan 15, 2022 8:12 am

I thought Ctrl+C is only supposed to interrupt the main thread, not timers nor disable the irq-s. Can someone confirm the opposite?
Aivar Annamaa
https://thonny.org

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: can't stop Timer in Thonny

Post by Roberthh » 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.

y1ngkhun
Posts: 7
Joined: Thu Jul 08, 2021 7:49 am

Re: can't stop Timer in Thonny

Post by y1ngkhun » Sun Jan 16, 2022 8:21 am

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 :(

User avatar
aivarannamaa
Posts: 171
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

Re: can't stop Timer in Thonny

Post by aivarannamaa » Sun Jan 16, 2022 10:33 am

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).
Aivar Annamaa
https://thonny.org

Jibun no kage
Posts: 144
Joined: Mon Jul 25, 2022 9:45 pm

Re: can't stop Timer in Thonny

Post by Jibun no kage » Sat Aug 20, 2022 5:27 pm

Example of how to disable irq-s?

Post Reply