Hi,
I'm new to MicroPython, so definitely could be missing something, but it seems that whenever I'm running `ampy` or `rshell` they constantly keep running `boot.py` and `main.py`.
I see that for every `ampy` command, even just `ls`, and with `rshell` I notice that when it starts, it tries to initialize different variables from the board itself (name, chip_type, even the list of files under '/'), and it seems that for every such command, it runs boot+main.
This causes me several problems:
1. This is slow. I'm initializing network, sdcard and other peripherals in boot.py and main.py, so it does so repeatedly, even without I need that for the command itself.
2. If I have a bug in main.py it could make these stuck and sometimes I even need to erase flash and copy a "commented-out" main.
[*] Do `ampy` and `rshell` really need to run the init scripts?
[*] Is there a flag to turn that off?
[*] If not - what should be my best practice? On one hand - my app needs the initializations (network, sdcard,...), but on the other hand I don't need them just for copying files, or testing another new module. Can I have 2 "modes" for boot?
Thanks!
Zach
Why do `rshell` and `ampy` run boot.py and main.py for every command?
-
- Posts: 15
- Joined: Tue Aug 09, 2022 11:32 am
Re: Why do `rshell` and `ampy` run boot.py and main.py for every command?
I am not sure if i understand you correctly but this is what i use to run the main.py on the pyboard.
Download the following micropython github repo.
https://github.com/micropython/micropython
From this github repo there is a folder tools which has pyboard.py. You can use this to start main.py or any other python file on your device.
The command i use is:
Download the following micropython github repo.
https://github.com/micropython/micropython
From this github repo there is a folder tools which has pyboard.py. You can use this to start main.py or any other python file on your device.
The command i use is:
Code: Select all
python pyboard.py --device COM10 h:\main.py
Re: Why do `rshell` and `ampy` run boot.py and main.py for every command?
I don't know much about ampy or rshell, but what you're describing definitely doesn't happen with mpremote (or pyboard.py).
I would definitely recommend mpremote -- see https://docs.micropython.org/en/latest/ ... emote.html
Re: Why do `rshell` and `ampy` run boot.py and main.py for every command?
rshell does whatever pyboard.py does (since it uses pyboard.py to do all of the low level stuff).
When micropython boots up it runs boot.py and then if it's running the raw REPL it will skip running main.py
https://github.com/micropython/micropyt ... #L223-L247
rshell, pyboard.py and mpremote all use the raw repl, so for all of these you should see that boot.py gets run but main.py doesn't.
The intention of boot.py is do very limited hardware setup (mount SD card, configure USB), and these are the types of things that rshell/pyboard.py/mpremote would want setup. Additional setup that takes a long time, should happen in main.py and then it won't happen once rshell/pyboard.py/mpremote is connected.
When micropython boots up it runs boot.py and then if it's running the raw REPL it will skip running main.py
https://github.com/micropython/micropyt ... #L223-L247
rshell, pyboard.py and mpremote all use the raw repl, so for all of these you should see that boot.py gets run but main.py doesn't.
The intention of boot.py is do very limited hardware setup (mount SD card, configure USB), and these are the types of things that rshell/pyboard.py/mpremote would want setup. Additional setup that takes a long time, should happen in main.py and then it won't happen once rshell/pyboard.py/mpremote is connected.