← index #8586Issue #10099
Related · high · value 0.604
QUERY · ISSUE

Long Timer Never Gets Called

openby patrick-collinsopened 2022-04-25updated 2022-04-26
port-rp2

On a Raspberry Pico a timer with a period of 300000 (5 minutes) gets called reliably while another timer with a period of 900000 (15 minutes) never gets called. Changing the period of task3 to 300000 gets it working again.

task1 = Timer()
task2 = Timer()
task3 = Timer()
task1.init(period=60000, mode=Timer.PERIODIC, callback=get_gnss)
task2.init(period=300000, mode=Timer.PERIODIC, callback=get_temperature)
task3.init(period=900000, mode=Timer.PERIODIC, callback=put_data)

CANDIDATE · ISSUE

Software timer misfiring after gc.collect()

closedby intx82opened 2022-11-26updated 2022-11-27
bugport-rp2

Hi guys

My board is RP-Pico with firmware:

MicroPython v1.19.1 on 2022-10-14; Raspberry Pi Pico with RP2040
Type "help()" for more information.

I found an issue related to garbage collector which break a timer if a timer was created as a local variable.
For example:

def test():
    Timer(period=10000, mode=Timer.ONE_SHOT, callback=lambda t: print(t))

>>> test()
>>> Timer(mode=ONE_SHOT, period=268687648, tick_hz=1000000)

>>>
>>> test()
>>> gc.collect()
...
# and after 10secs there is no print message

It's sounds like, garbage collector freed timer, and this should happen because timer was a local variable. But from the other side, it's a mistake due to the timer never fired up.

Is this bug or feature? Which behavior is right?

As for me, more delicate solution will be clearing already finished timers.

If it's a bug, i will try to make some pull request to fix it.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied