> Will the BOOT.PY run before Thonny downloads and runs the MAIN.PY?
I assume that by "downloading main.py" you mean saving some code as main.py on the device. Please note just saving main.py does not run anything -- for Thonny these are different actions. Thonny allows you to run the editor content directly with the green arrow button or F5 key -- in this case nothing gets saved on the device. Alternatively, you can save the editor content to the main.py on the device but in this case nothing gets executed automatically. If you want to run the main.py as it is on the device (regardless of what do you currently have in the editor), you can press Ctrl-D to soft reboot your device.
Every time you power on your device or press Ctrl-D on idle prompt, your device first executes boot.py and then main.py. Please note that when you connect to your device in Thonny before boot.py has completed, then with the default settings (with "Interrupt working program on connect" checked) it will be interrupted.
What happens when you run the editor content in Thonny, depends on another setting -- "Restart interpreter before running a script". If this is checked, then Thonny first puts you device's REPL into raw mode and then performs a soft-reboot. In this mode soft-reboot only runs boot.py, not main.py. After boot.py has completed, Thonny sends whatever you have in the active editor to be executed on your device. If this setting is OFF, then Thonny executes the editor content right away, i.e. with the global state your device happens to have at this moment.
I now realized the users may get confused by this, because currently Thonny surpresses the output from boot.py in case of these soft-reboots. I'll change this in the next Thonny version (https://github.com/thonny/thonny/issues/2655).
"Restart interpreter before running a script" is ON by default, because I assume in general people want to start their program in a consistent state, without being affected by the leftovers of previous runs or REPL commands. It is optional, because sometimes soft-reboot can be too slow. For example, when you put the WiFi connection code in boot.py of ESP32 devices, it resets the connection and reconnects each time (at least with some MicroPython versions). With Pico W this doesn't seem to be the case -- according to my experiments, Pico W keeps the Wifi connection over soft-reboots, so if you have managed to create the connection once, doing it again after the soft-reboot will be very quick (until the next hard-boot, of course).
Best regards,
Aivar