-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib/utils/pyexec: Don't treat SystemExit as "forced exit". #2495
Conversation
"Forced exit" is treated as soft-reboot (Ctrl+D). But expected effect of calling sys.exit() is termination of the current script, not any further and more serious actions like mentioned soft reboot.
I don't know how we ended with treating SystemExit as a reboot, but time to break that tradition ;-). As outcome of porting upip to baremetal. |
We had a soft reboot and a hard reboot function for the pyboard, and we decided that throwing a SystemExit would be better than having a softreboot function, and since that's all that sys.exit does that's what we did. See: #826 |
See also #924. If we remove this behaviour (SystemExit not doing a soft reset) then we'll need to add machine.soft_reset(), or something similar, as a programatic way to do soft reset. |
If somebody wants the SystemExit exception to do something different, then you just need to intercept the exception and do what you want and you won't get the soft reset behaviour. |
What command can I use to get back to the REPL then? |
If you leave main.py then you return to the REPL. |
How can you leave main.py from the middle of your function? |
If I write my main.py something like this:
Then you can raise MyException from anywhere in the program and you will leave main.py Using the function main is completely optional. But as soon as execution returns from main.py then the REPL is executed. |
I see, that could work. |
If we remove this behaviour (SystemExit not doing a soft reset) then
we'll need to add machine.soft_reset(), or something similar, as a
programatic way to do soft reset.
Sounds good, can you please prepare that?
|
If somebody wants the SystemExit exception to do something different,
then you just need to intercept the exception and do what you want
and you won't get the soft reset behaviour.
The problem is that people exactly don't want SystemExit to do
something different to what it's supposed to do. And that's: 1)
terminate currently running application (being done); 2) drop to
"command line" - not being done, instead, something else is done.
|
We could add |
I don't see a big inconsistency here. There's a real reset, and "soft reset", which isn't even available (fully) for each target.
Ack, I'd say that's going down the rabit hole. If soft reset is so important, let it be a top-level function. I personally know only one important usage for it - soft-resetting between tests when running on-device testsuite. Otherwise, it's optional, convenience feature.
+1 |
Ok, to have further progress on this, I'm going to merge this (to prepare upip for esp8266 for release), and created #2508 for machine.soft_reset() part. |
"Forced exit" is treated as soft-reboot (Ctrl+D). But expected effect of
calling sys.exit() is termination of the current script, not any further
and more serious actions like mentioned soft reboot.