diff options
author | David Lechner <david@pybricks.com> | 2021-05-10 22:18:17 -0500 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-06-19 09:49:00 +1000 |
commit | 259d9b69fe1f0e5c473bad85755d59233e0d182e (patch) | |
tree | e420d35ab69cc79e4067010fd48bfb57bf8f8489 /py/mpstate.h | |
parent | ca920f72184c50f61002aa9d5cd01555b1e28b7b (diff) |
py/mpstate: Schedule KeyboardInterrupt on main thread.
This introduces a new macro to get the main thread and uses it to ensure
that asynchronous exceptions such as KeyboardInterrupt (CTRL+C) are only
scheduled on the main thread. This is more deterministic than being
scheduled on a random thread and is more in line with CPython that only
allow signal handlers to run on the main thread.
Fixes issue #7026.
Signed-off-by: David Lechner <david@pybricks.com>
Diffstat (limited to 'py/mpstate.h')
-rw-r--r-- | py/mpstate.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/py/mpstate.h b/py/mpstate.h index f5fb5b707..e42d13fb2 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -285,12 +285,13 @@ extern mp_state_ctx_t mp_state_ctx; #define MP_STATE_VM(x) (mp_state_ctx.vm.x) #define MP_STATE_MEM(x) (mp_state_ctx.mem.x) +#define MP_STATE_MAIN_THREAD(x) (mp_state_ctx.thread.x) #if MICROPY_PY_THREAD extern mp_state_thread_t *mp_thread_get_state(void); #define MP_STATE_THREAD(x) (mp_thread_get_state()->x) #else -#define MP_STATE_THREAD(x) (mp_state_ctx.thread.x) +#define MP_STATE_THREAD(x) MP_STATE_MAIN_THREAD(x) #endif #endif // MICROPY_INCLUDED_PY_MPSTATE_H |