Skip to content

Commit dbf1bef

Browse files
committed
watchdog: support catching the timeout
With this patch, the exception can now be caught: import microcontroller import watchdog import time wdt = microcontroller.watchdog wdt.timeout = 5 while True: wdt.mode = watchdog.WatchDogMode.RAISE print("Starting loop -- should exit after five seconds") try: while True: time.sleep(10) # pass # This also works for a spinloop except watchdog.WatchDogTimeout as e: print("Watchdog Expired (PASS)") except Exception as e: print("Other exception (FAIL)") print("Exited loop") This prints: Starting loop -- should exit after five seconds Watchdog Expired (PASS) Starting loop -- should exit after five seconds Watchdog Expired (PASS) Starting loop -- should exit after five seconds Watchdog Expired (PASS) Signed-off-by: Sean Cross <[email protected]>
1 parent e470376 commit dbf1bef

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

shared-bindings/watchdog/__init__.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ mp_obj_exception_t mp_watchdog_timeout_exception = {
7474
STATIC const mp_rom_map_elem_t watchdog_module_globals_table[] = {
7575
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_watchdog) },
7676
{ MP_ROM_QSTR(MP_QSTR_WatchDogMode), MP_ROM_PTR(&watchdog_watchdogmode_type) },
77+
{ MP_ROM_QSTR(MP_QSTR_WatchDogTimeout), MP_ROM_PTR(&mp_type_WatchDogTimeout) },
7778
};
7879

7980
STATIC MP_DEFINE_CONST_DICT(watchdog_module_globals, watchdog_module_globals_table);

0 commit comments

Comments
 (0)