8000 Introduce machine.soft_reset() · Issue #2508 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

Introduce machine.soft_reset() #2508

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

Closed
pfalcon opened this issue Oct 12, 2016 · 13 comments
Closed

Introduce machine.soft_reset() #2508

pfalcon opened this issue Oct 12, 2016 · 13 comments

Comments

@pfalcon
Copy link
Contributor
pfalcon commented Oct 12, 2016

As discussed in #2495

@dpgeorge
Copy link
Member

It's not that easy to implement. Simplest thing would be to do what was previously done with SystemExit: machine.soft_reset() would set a special flag saying that there should be a soft reset, and then it would raise SystemExit. Assuming the script does not intercept the exception, it would propagate to the pyexec function, which needs to then return another special value (like it did before) to indicate to the caller that SystemExit was raised. Then finally the caller would check the soft reset flag and do a soft reset.

@pfalcon
Copy link
Contributor Author
pfalcon commented Oct 13, 2016

So, do we want to leave this for after 1.8.5?

@dpgeorge
Copy link
Member

I'd rather not have this feature missing (at least for pyboard/stmhal) in a release. I'll try to add something that at least works, and we can have further discussion later if needed.

@dhylands
Copy link
Contributor

It isn't clear to me what the desired sys.exit() behaviour should be (aside from what it currently is) for something like the pyboard. I think that under unix, it should quit the app.

@pfalcon
Copy link
Contributor Author
pfalcon commented Oct 13, 2016

Same for any other port.

@dhylands
Copy link
Contributor

Same for any other port.

which is what exactly?

There are 2 different classes of machines here, one where you have the ability to exit the process (i.e. unix) and one where you don't (i.e. the pyboard doesn't have the notion of a process).

@pfalcon
Copy link
Contributor Author
pfalcon commented Oct 13, 2016

#2495 (comment)

@dhylands
Copy link
Contributor

#2495 (comment)

Actually, under linux, sys.exit() doesn't "drop to command line" unless the caller happens to be a shell.

And since there is no command line on the pyboard what exactly does "drop to the command line" mean?

@pfalcon
Copy link
Contributor Author
pfalcon commented Oct 13, 2016

It means the behavior of the current micropython master.

@dhylands
Copy link
Contributor

Now I'm totally confused. You want to change the behaviour of sys.exit() to be what it currently is?

@dpgeorge
Copy link
Member

The point is that sys.exit() (and hence raise SystemExit) should just "stop the running code" / "quit the app", and shouldn't lead to extra behaviour like restarting the board and rerunning start-up scripts, for example. This distinction was not really a problem with pyboard, but with the esp8266 it can't properly handle a soft reset, and soft-resetting in WebREPL doesn't work at all (because the start-up scripts initialise the WebREPL).

As such, we need to make the behaviour of SystemExit more fine-grained / decomposed: the exiting of the script/app should be independent to an actual soft reset. So SystemExit will now just finish the script (and drop to a REPL on bare-metal, since there's not much else it can do).

See ad3724e and 57226a2 for implementation of machine.soft_reset() in stmhal. We can factor that out to all ports when we agree on the behaviour (and keep this ticket open until then).

@gengshenghong
Copy link

Agree to introduce soft_reset for esp32. 👍

Thanks,
Shenghong

@dpgeorge
Copy link
Member

machine.soft_reset() was added to the docs in 1caede9, and implemented on esp32 in 6632dd3

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

No branches or pull requests

4 participants
0