Skip to content

Commit f5c6f7a

Browse files
committed
docs,extmod: Deprecate machine.soft_reset().
Encourage calling sys.exit() instead, mark machine.soft_reset() for removal in MicroPython 2.0. Adds some additional explanation of SystemExit in the MicroPython context. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent f1d629b commit f5c6f7a

File tree

6 files changed

+17
-3
lines changed

6 files changed

+17
-3
lines changed

docs/library/builtins.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ Exceptions
194194

195195
|see_cpython| `python:SystemExit`.
196196

197+
On non-embedded ports (i.e. Windows and Unix), an unhandled ``SystemExit``
198+
exits the MicroPython process in a similar way to CPython.
199+
200+
On embedded ports, an unhandled ``SystemExit`` causes a :ref:`soft_reset` of
201+
MicroPython.
202+
197203
.. exception:: TypeError
198204

199205
|see_cpython| `python:TypeError`.

docs/library/machine.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ Reset related functions
7070
Performs a :ref:`soft reset <soft_reset>` of the interpreter, deleting all
7171
Python objects and resetting the Python heap.
7272

73+
.. note:: This function is deprecated. Call the Python standard
74+
:func:`sys.exit()` function instead.
75+
7376
.. function:: reset_cause()
7477

7578
Get the reset cause. See :ref:`constants <machine_constants>` for the possible return values.

docs/library/sys.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ Functions
1212
.. function:: exit(retval=0, /)
1313

1414
Terminate current program with a given exit code. Underlyingly, this
15-
function raise as `SystemExit` exception. If an argument is given, its
15+
function raises a `SystemExit` exception. If an argument is given, its
1616
value given as an argument to `SystemExit`.
1717

18+
On embedded ports (i.e. all ports but Windows and Unix), an unhandled
19+
`SystemExit` triggers a :ref:`soft_reset` of MicroPython.
20+
1821
.. function:: atexit(func)
1922

2023
Register *func* to be called upon termination. *func* must be a callable

docs/reference/repl.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ method by which you're connected to the MicroPython board (USB-serial, or Wifi).
154154
You can perform a soft reset from the REPL by pressing Ctrl-D, or from your python
155155
code by executing: ::
156156

157-
machine.soft_reset()
157+
sys.exit()
158158

159159
For example, if you reset your MicroPython board, and you execute a dir()
160160
command, you'd see something like this:

docs/reference/reset_boot.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Soft Reset
2424

2525
When MicroPython is already running, it's possible to trigger a soft reset by
2626
:ref:`typing Ctrl-D in the REPL <repl_soft_reset>` or executing
27-
:func:`machine.soft_reset()`.
27+
:func:`sys.exit()`.
2828

2929
A soft reset clears the Python interpreter, frees all Python memory, and starts
3030
the MicroPython environment again.

extmod/modmachine.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ static const mp_rom_map_elem_t machine_module_globals_table[] = {
156156
#endif
157157

158158
// Reset related functions.
159+
#if !MICROPY_PREVIEW_VERSION_2
159160
{ MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&mp_sys_exit_obj) },
161+
#endif
160162
#if MICROPY_PY_MACHINE_BOOTLOADER
161163
{ MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) },
162164
#endif

0 commit comments

Comments
 (0)