Skip to content

Commit 304fa1a

Browse files
Improve robustness with custom exception that does not deinit() the TaskHandler
1 parent c62b30b commit 304fa1a

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- WiFi app: check "hidden" in EditNetwork
66
- Wifi app: add support for scanning wifi QR codes to "Add Network"
77
- Improve robustness by catching unhandled app exceptions
8+
- Improve robustness with custom exception that does not deinit() the TaskHandler
9+
- Improve robustness by removing TaskHandler callback that throws an uncaught exception
810

911
0.5.2
1012
=====

internal_filesystem/lib/mpos/main.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,27 @@
5151
if focusgroup: # on esp32 this may not be set
5252
focusgroup.remove_all_objs() # might be better to save and restore the group for "back" actions
5353

54-
# Can be passed to TaskHandler, currently unused:
54+
# Custom exception handler that does not deinit() the TaskHandler because then the UI hangs:
5555
def custom_exception_handler(e):
56-
print(f"custom_exception_handler called: {e}")
57-
mpos.ui.task_handler.deinit()
56+
print(f"TaskHandler's custom_exception_handler called: {e}")
57+
import sys
58+
sys.print_exception(e) # NOQA
59+
# No need to deinit() and re-init LVGL:
60+
#mpos.ui.task_handler.deinit() # default task handler does this, but then things hang
5861
# otherwise it does focus_next and then crashes while doing lv.deinit()
59-
focusgroup.remove_all_objs()
60-
focusgroup.delete()
61-
lv.deinit()
62+
#focusgroup.remove_all_objs()
63+
#focusgroup.delete()
64+
#lv.deinit()
6265

6366
import sys
6467
if sys.platform == "esp32":
65-
mpos.ui.task_handler = task_handler.TaskHandler(duration=5) # 1ms gives highest framerate on esp32-s3's but might have side effects?
68+
mpos.ui.task_handler = task_handler.TaskHandler(duration=5, exception_hook=custom_exception_handler) # 1ms gives highest framerate on esp32-s3's but might have side effects?
6669
else:
67-
mpos.ui.task_handler = task_handler.TaskHandler(duration=5) # 5ms is recommended for MicroPython+LVGL on desktop (less results in lower framerate)
70+
mpos.ui.task_handler = task_handler.TaskHandler(duration=5, exception_hook=custom_exception_handler) # 5ms is recommended for MicroPython+LVGL on desktop (less results in lower framerate)
71+
72+
# Convenient for apps to be able to access these:
73+
mpos.ui.task_handler.TASK_HANDLER_STARTED = task_handler.TASK_HANDLER_STARTED
74+
mpos.ui.task_handler.TASK_HANDLER_FINISHED = task_handler.TASK_HANDLER_FINISHED
6875

6976
try:
7077
import freezefs_mount_builtin

scripts/build_mpos.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ elif [ "$target" == "unix" -o "$target" == "macOS" ]; then
143143
# Restore RLOTTIE:
144144
if [ "$target" == "unix" ]; then
145145
sed -i.backup 's/#define MICROPY_RLOTTIE 1/#define MICROPY_RLOTTIE 0/' "$codebasedir"/lvgl_micropython/lib/lv_conf.h
146-
echo "After disabling MICROPY_RLOTTIE:"
147-
cat "$codebasedir"/lvgl_micropython/lib/lv_conf.h
146+
#echo "After disabling MICROPY_RLOTTIE:"
147+
#cat "$codebasedir"/lvgl_micropython/lib/lv_conf.h
148148
fi
149149

150150
# Restore @micropython.viper decorator after build

0 commit comments

Comments
 (0)