forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
CircuitPython version
Adafruit CircuitPython 8.0.0-beta.6 on 2022-12-21; Adafruit QT Py ESP32S2 with ESP32S2Code/REPL
import time
import traceback
import alarm
import supervisor
def main():
print("Sleeping for 10 seconds")
time.sleep(10)
sleep_period = 15
time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + sleep_period)
print(f"Entering deep sleep for {sleep_period} seconds")
alarm.exit_and_deep_sleep_until_alarms(time_alarm)
try:
main()
except BaseException as e: # pylint: disable=broad-except
# This assumes that such exceptions are quite rare.
# Otherwise, this would drain the battery quickly by restarting
# over and over in a quick succession.
print("Code stopped by unhandled exception:")
print(traceback.format_exception(None, e, e.__traceback__))
RELOAD_TIME = 10
print(f"Performing a supervisor reload in {RELOAD_TIME} seconds")
time.sleep(RELOAD_TIME)
supervisor.reload()Behavior
The code crashes into hard fault handler. The QtPy has to be restarted by the reset button.
Description
The QtPy is connected to stable USB power source (my laptop) so in reality the deep sleep will not happen.
This is reproducible 100% of time.
My hypothesis is that the DeepSleepRequest gets raised by the alarm and given it is based on BaseException, the catch block will try to handle it and somehow this is toxic to the traceback line.
Additional information
If I replace the BaseException with just Exception, the code does not crash anymore and properly says Pretending to deep sleep until alarm, CTRL-C or file write..
More details on vladak/shield#14.