REPL does not stop boot.py
REPL does not stop boot.py
I have code running on a board (a pyboard but I don't think that's relevant) that simply uses a timer with a callback to flash a led. Works fine, starts running (because boot.py invokes it) every time I reset the board. However, if I start a REPL session by using Ctrl-C while that code is running, the code keeps on running and the led keeps flashing. I would have thought the REPL would have stopped any code running on the board and then cleared the code out of the board's RAM, ready to have new code entered, but it appears that is not happening, or that boot.py is being invoked again. How can the two sets of code run concurrently? What do I need to do to prevent this? Thanks.
Re: REPL does not stop boot.py
No. Entering the REPL doesn't clear out memory etc. Which is a good thing because it allows you to investigate things when your program crashes.
If you do a Soft Reset (i.e. Control-D) once you get into the REPL, then your program will be cleared out of memory.
You could also have your code use a try/catch to grab the KeyboardInterrupt and do a clean shutdown. Pressing Control-C will generate a KeyboardInterrupt exception.
If you do a Soft Reset (i.e. Control-D) once you get into the REPL, then your program will be cleared out of memory.
You could also have your code use a try/catch to grab the KeyboardInterrupt and do a clean shutdown. Pressing Control-C will generate a KeyboardInterrupt exception.
Re: REPL does not stop boot.py
OK, I see that's a good thing about the REPL, but if I use Ctrl-D when in the REPL it reboots the program. Here is the REPL session, with comments added:
KeyboardInterrupt:
MicroPython v1.11 on 2019-05-29; PYBv1.1 with STM32F405RG
Type "help()" for more information.
# test to see if in REPL
>>> 1+11
12
>>>
# Ctrl-D here
MPY: sync filesystems
MPY: soft reboot
Enter main loop <-- issued by my program
...leds flashing
KeyboardInterrupt:
MicroPython v1.11 on 2019-05-29; PYBv1.1 with STM32F405RG
Type "help()" for more information.
# test to see if in REPL
>>> 1+11
12
>>>
# Ctrl-D here
MPY: sync filesystems
MPY: soft reboot
Enter main loop <-- issued by my program
...leds flashing
Re: REPL does not stop boot.py
It turns out that if you do a Control-D from the raw REPL then main.py won't get executed.
So if you move your code to main.py instead of boot.py then you can do:
Control-A Control-D Control-B
and get into the REPL without main.py being executed. During development, I often use a jumper or pushbutton to indicate "run" mode and have main.py check the jumper and just exit to the REPL based on the jumper being present/absent
So if you move your code to main.py instead of boot.py then you can do:
Control-A Control-D Control-B
and get into the REPL without main.py being executed. During development, I often use a jumper or pushbutton to indicate "run" mode and have main.py check the jumper and just exit to the REPL based on the jumper being present/absent
Re: REPL does not stop boot.py
Thanks. I just have to remember "cadbee": Ctrl-C, Ctrl-A, Ctrl-D, Ctrl-B does it. I like your jumper technique; I'll give it a try.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: REPL does not stop boot.py
My approach is not to touch main.py until my application is debugged. Say the application is in my_app.py - it can be tested by issuing
at the REPL, interrupted with ctrl-c and cleared out of RAM with ctrl-d. Once it's tested and ready to deploy, main.py simply requires the above one-liner for it to auto-run.
Code: Select all
import my_app
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.