Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

pfalcon
Copy link
Contributor

@pfalcon pfalcon commented Oct 8, 2016

"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.

"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.
@pfalcon
Copy link
Contributor Author

pfalcon commented Oct 8, 2016

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.

@dhylands
Copy link
Contributor

dhylands commented Oct 8, 2016

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

@dpgeorge
Copy link
Member

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.

@dhylands
Copy link
Contributor

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.

@deshipu
Copy link
Contributor

deshipu commented Oct 10, 2016

What command can I use to get back to the REPL then?

@dhylands
Copy link
Contributor

What command can I use to get back to the REPL then?

If you leave main.py then you return to the REPL.

@deshipu
Copy link
Contributor

deshipu commented Oct 10, 2016

How can you leave main.py from the middle of your function?

@dhylands
Copy link
Contributor

If I write my main.py something like this:

def main():
    try:
        # do some stuff
     except MyException:
         return

main()
print('After this the REPL will be executed')

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.

@deshipu
Copy link
Contributor

deshipu commented Oct 10, 2016

I see, that could work.

@pfalcon
Copy link
Contributor Author

pfalcon commented Oct 10, 2016 via email

@pfalcon
Copy link
Contributor Author

pfalcon commented Oct 10, 2016 via email

@dpgeorge dpgeorge mentioned this pull request Oct 10, 2016
@dpgeorge
Copy link
Member

We could add machine.soft_reset(). But then it's arguably a tiny bit inconsistent with machine.reset() which should then be called machine.hard_reset(). Instead we could add an argument to the existing machine.reset() which indicates what kind of reset (eg hard, soft, with default being hard). But then you'd need constants for the kind of reset. It could be a boolean, ie machine.reset(soft=True) but that's not very friendly. Probably machine.soft_reset() is the right thing to do.

@pfalcon
Copy link
Contributor Author

pfalcon commented Oct 11, 2016

We could add machine.soft_reset(). But then it's arguably a tiny bit inconsistent with machine.reset() which should then be called machine.hard_reset().

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.

Instead we could add an argument to the existing machine.reset() which indicates what kind of reset (eg hard, soft, with default being hard). But then you'd need constants for the kind of reset. It could be a boolean, ie machine.reset(soft=True) but that's not very friendly.

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.

Probably machine.soft_reset() is the right thing to do.

+1

@pfalcon
Copy link
Contributor Author

pfalcon commented Oct 12, 2016

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.

@pfalcon pfalcon closed this Oct 12, 2016
@pfalcon pfalcon deleted the SystemExit-no-reboot branch October 12, 2016 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants