From f80c6c740453507cc321571a9163252452f4743b Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Fri, 22 Nov 2024 17:26:09 +1100 Subject: [PATCH] shared/runtime/pyexec: Integrate atexit to be run during exit process. Signed-off-by: Andrew Leech --- shared/runtime/pyexec.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shared/runtime/pyexec.c b/shared/runtime/pyexec.c index 4e15d5e9ecf0..9712ddc28e5e 100644 --- a/shared/runtime/pyexec.c +++ b/shared/runtime/pyexec.c @@ -34,6 +34,7 @@ #include "py/repl.h" #include "py/gc.h" #include "py/frozenmod.h" +#include "py/modatexit.h" #include "py/mphal.h" #if MICROPY_HW_ENABLE_USB #include "irq.h" @@ -188,6 +189,11 @@ static int parse_compile_execute(const void *source, mp_parse_input_kind_t input mp_hal_stdout_tx_strn("\x04", 1); } + #if MICROPY_PY_ATEXIT + int atexit_code = mp_atexit_execute(); + ret = (atexit_code != 0) ? atexit_code : ret; + #endif + #ifdef MICROPY_BOARD_AFTER_PYTHON_EXEC MICROPY_BOARD_AFTER_PYTHON_EXEC(input_kind, exec_flags, nlr.ret_val, &ret); #endif