diff options
| author | John Smith <jsmith@jsmith.cz> | 2024-08-29 10:29:35 +0200 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-11-04 16:47:19 +1100 |
| commit | 1e5da2642cbb0b4c808323173b7a703c3a3cf24f (patch) | |
| tree | 4cfc767e94bb2ba2e5570e6effaeea2fc84539fd /shared/runtime/pyexec.h | |
| parent | 4f2f520dc282f3b666e29aa7f316932cc9af8016 (diff) | |
shared/runtime: Set exit code according to the SystemExit exception.
Add abort setup code `nlr_set_abort` to the standard runtime executor.
This makes the standard runtime respond to abort signal without any further
modifications.
- When aborted, the program exits with 137 exit code (configurable, same as
posix sig abort), to differentiate from a normal shutdown.
- When exited by exception/crash, the program will exit with exit code 1
(configurable).
- When exited by exception KeyboardInterrupt, the program will exit with
exit code 130 (configurable, same as posix sig int).
- When exited with a exit code (from Python environment), this code is
propagated. When a different object is passed, exit code is set to 1 and
the value printed, to be consistent with Python docs:
https://python.readthedocs.io/en/latest/library/exceptions.html#SystemExit
Signed-off-by: John Smith <jsmith@jsmith.cz>
Diffstat (limited to 'shared/runtime/pyexec.h')
| -rw-r--r-- | shared/runtime/pyexec.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/shared/runtime/pyexec.h b/shared/runtime/pyexec.h index 95f448162..fb52c09b1 100644 --- a/shared/runtime/pyexec.h +++ b/shared/runtime/pyexec.h @@ -37,6 +37,17 @@ extern pyexec_mode_kind_t pyexec_mode_kind; #define PYEXEC_FORCED_EXIT (0x100) +#if MICROPY_PYEXEC_ENABLE_EXIT_CODE_HANDLING +#define PYEXEC_NORMAL_EXIT (0) +#define PYEXEC_UNHANDLED_EXCEPTION (1) +#define PYEXEC_KEYBOARD_INTERRUPT (128 + 2) // same as SIG INT exit code +#define PYEXEC_ABORT (128 + 9) // same as SIG KILL exit code +#else +#define PYEXEC_NORMAL_EXIT (1) +#define PYEXEC_UNHANDLED_EXCEPTION (0) +#define PYEXEC_ABORT PYEXEC_FORCED_EXIT +#endif + int pyexec_raw_repl(void); int pyexec_friendly_repl(void); int pyexec_file(const char *filename); |
