boot.py versus main.py
I’m having a little trouble understanding why there are separate
main.pyfiles. In my testing, both are executed every time the board boots, is reset, and wakes from deep sleep. Is there ever a time when one is executed and not the other? Any guidelines or rules of thumb on when to prefer putting code in one over the other? Barring that, my inclination is to leave
boot.pystock and put all of my application in
@tshead Boot.py and main.py are executed in exactly the same context one after the other. So you can put your code into either one. To be more detailed, there are four scripts which are potentially run on boot:
- _boot.py which has to reside in flash
- boot.py which must be in the file system
- _main.py which is expected inside the flash
- main.py (or other) which again must be in the file system.
Steps 2. -4. are skipped during safeboot. step 4 is only executed in the so called PYEXEC_MODE_FRIENDLY_REPL, which is the normal REPL mode after boot. 3. was added to allow people to put their main.py into the flash memory.
@robert-hh - thanks for the clarification, I hadn’t noticed
machine.main(). While it’s nice that you can choose to execute a different file, that doesn’t really address the question of why I’d split my app into two separate files to begin with. Are there operations that can only be performed in
boot.py? Operations that can’t be performed there? Does something special happen between execution of