summaryrefslogtreecommitdiff
path: root/py/runtime.c
diff options
context:
space:
mode:
authorMilan Rossa <rossa.milan@gmail.com>2019-08-05 15:06:41 +0200
committerDamien George <damien.p.george@gmail.com>2019-08-15 17:30:50 +1000
commitcb3647004fbf7b069a3509a02b72420828369bd3 (patch)
tree403306b62da8464cb3ac5d3a59404c6669f8e6f1 /py/runtime.c
parent2ccf030fd1ee7ddf7c015217c7fbc9996c735fd1 (diff)
py: Implement new sys.atexit feature.
This patch implements a new sys.atexit function which registers a function that is later executed when the main script ends. It is configurable via MICROPY_PY_SYS_ATEXIT, disabled by default. This is not compliant with CPython, rather it can be used to implement a CPython compatible "atexit" module if desired (similar to how sys.print_exception can be used to implement functionality of the "traceback" module).
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/py/runtime.c b/py/runtime.c
index 70d795719..04f9442b7 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -118,6 +118,10 @@ void mp_init(void) {
MP_STATE_VM(vfs_mount_table) = NULL;
#endif
+ #if MICROPY_PY_SYS_ATEXIT
+ MP_STATE_VM(sys_exitfunc) = mp_const_none;
+ #endif
+
#if MICROPY_PY_THREAD_GIL
mp_thread_mutex_init(&MP_STATE_VM(gil_mutex));
#endif