← index #4458Issue #7433
Related · high · value 0.278
QUERY · ISSUE

Various unexpeced errors, if initialized timer is not referenced by pythoncode

openby JohnMTuopened 2019-02-03updated 2026-03-24
proposed-close

When Timer is initialized, but instance is no longer referenced from python code, it's probably subject for GC.
Unfortunatelly after GC there are unexpected errors, when timer should fire.
Most probably underlaying RTOS or c++ code is still trying to reference memory, which was used by python Timer object, which is now gone.

initial topic: https://forum.micropython.org/viewtopic.php?f=2&t=5898&p=33812#p33812

CANDIDATE · ISSUE

RP2: Unexpected behaviour if allocation occurs in ISR

closedby peterhinchopened 2021-06-20updated 2021-06-23

Most platforms raise an exception if an ISR attempts allocation. RP2 fails silently.

from machine import Pin, PWM,Timer
import time
a = 1.0
def ns(_):
    global a
    a *= 1.1

t1= Timer()
t1.init(freq =8000, mode = Timer.PERIODIC, callback =ns)

while True:
    print(a)
    time.sleep(1)

Result:

1.0
inf
inf
inf
inf

This behaviour is confusing: arguably an exception should be raised.

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