Is it possible to detect when the REPL is logged into, my guess is no.
When a user logs into the REPL I want to trigger a soft reboot, or even import a file.
Execute file when REPL is entered
Re: Execute file when REPL is entered
I guess it depends on what exactly you mean by "logged into the REPL" since the REPL doesn't have any real notion of logging in.
The REPL will be entered as soon as main.py exits, or otherwise throws an error.
So you could put a try/catch around your main.py execution and if the catch executes then it will execute just before the REPL is entered.
Detecting that a user (i.e. host pc) is connected to the REPL is much more difficult (and probably impossible in general). Some devices can detect if a USB cable is plugged in, but that doesn't mean that any program running on the host actually has the serial port open.
The REPL will be entered as soon as main.py exits, or otherwise throws an error.
So you could put a try/catch around your main.py execution and if the catch executes then it will execute just before the REPL is entered.
Detecting that a user (i.e. host pc) is connected to the REPL is much more difficult (and probably impossible in general). Some devices can detect if a USB cable is plugged in, but that doesn't mean that any program running on the host actually has the serial port open.