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/scheduler.c | |
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/scheduler.c')
-rw-r--r-- | py/scheduler.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/py/scheduler.c b/py/scheduler.c index 0114a7a58..bd0bbf207 100644 --- a/py/scheduler.c +++ b/py/scheduler.c @@ -28,8 +28,10 @@ #include "py/runtime.h" +// Schedules an exception on the main thread (for exceptions "thrown" by async +// sources such as interrupts and UNIX signal handlers). void MICROPY_WRAP_MP_SCHED_EXCEPTION(mp_sched_exception)(mp_obj_t exc) { - MP_STATE_THREAD(mp_pending_exception) = exc; + MP_STATE_MAIN_THREAD(mp_pending_exception) = exc; #if MICROPY_ENABLE_SCHEDULER if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) { MP_STATE_VM(sched_state) = MP_SCHED_PENDING; |