microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
41 stars 22 forks source link

Scheduled calls from `run_every` are queued during sleep when `deep_sleep(run_every=False)` #131

Closed microbit-carlos closed 1 year ago

microbit-carlos commented 1 year ago

So a programme like this one, which purposely turns off the run_every events during sleep, will wake up and run the print_time() function 5 times in a row:

from microbit import *
import power

@run_every(s=3)
def print_time():
    print(running_time())
    display.show([Image.HEART, Image.HEART_SMALL])

while True:
    power.deep_sleep(15_000, run_every=False)

The heart animation can be seen 5 times, and this is printed to serial:

15182
15985
16789
17593
18397

I think in the occasions when deep_sleep is set up with run_every=False, we wouldn't expect the events to still be queued and all of them run when it wakes up, as the board might be put to sleep for long periods of time (for example, a data logging app that is meant to be deployed somewhere and start/stop logging when a button is pressed).

microbit-carlos commented 1 year ago

@dpgeorge could you have a look at this one?

dpgeorge commented 1 year ago

Fixed by 769a90d6adf9e3fec5b3eadd6e153c674c3b57c6