1

I'm trying to debug a circuitpython program (that's running on a microcontroller) and I would like to know if there's a simple way to get the program to drop into the REPL upon a crash/termination while preserving the variables and functions defined in the script.

If this was a regular python program I would simply run it with the "interactive" option of the interpreter set : python -i my_code.py and then have access the variables and function defined in my code for easy debugging.

Instead what I get right now is: after a crash I get prompted to press a key to enter the REPL but the memory is cleared from any trace of my previously running code.

jadsq
  • 3,033
  • 3
  • 20
  • 32

1 Answers1

1

A somewhat cumbersome way to achive an equivalent behaviour, that only works if the code terminates and doesn't crash, is to proceed as follows :

  1. Upload the code

  2. Code will start running automatically

  3. Interupt the code with a keyboard interupt

  4. Press a key to get to the REPL

  5. Import all from the code from the REPL by typing in:

    from code import *
    
  6. Wait for the code to terminate

  7. Finally debug

  8. Rince and repeat for each bug you find...

jadsq
  • 3,033
  • 3
  • 20
  • 32
  • 1
    I don't know about other boards, but if you are using a RPi Pico, simply don't name your file `main.py`. Then you can skip the entire interrupt process and start your program from the REPL to begin with. – OneMadGypsy Apr 15 '21 at 17:56
  • @Michael Guidry `main.py` and `code.py` both works. – River Oct 06 '21 at 14:42