← index #4458PR #17036
Off-topic · high · value 0.713
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 · PULL REQUEST

esp32/machine.timer.c: Fix timer.value() of an uninitialized timer.

mergedby robert-hhopened 2025-03-29updated 2025-05-14
port-esp32

Summary

Raises a value error in that case, which happens after a timer was created but not initialized or after calling timer.deinit(). Fixes issue #17033 / #17035.

Testing

Tested with a ESP32_GENERIC before and after the change, for both a) the state after creating the timer but not initializing it, and b) after calling timer.deinit() on a previously operating timer. In both states, the change causes the error to be raised.

Testing with a generic ESP32 seems to be sufficient, since the change is not specific for a ESP32 variant.

Trade-offs and Alternatives

Alternatively a neutral value like 0 or -1 could be returned instead of raising an error.

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