I've got an ESP8266 with Micropython which is counting pulses. The pulses are count in an Interrupt Handler. They can be many and eventually they could be more than sys.maxize (2147483647). In the micropython manual I can read that:
https://docs.micropython.org/en/latest/ ... rules.htmlMicroPython supports integers of arbitrary precision. Values between 2**30 -1 and -2**30 will be stored in a single machine word. Larger values are stored as Python objects. Consequently changes to long integers cannot be considered atomic. The use of long integers in ISR’s is unsafe because memory allocation may be attempted as the variable’s value changes.
I tried to trigger such event but I'm not able to get a number which is not type int:
Even triying to trigger the problem did not work:>>> a = 4564648646845648648648646
>>> type(a)
<class 'int'>
>>> a = 1
>>> type(a)
<class 'int'>
Can anyone bring some light into this?import time
import machine
# Test if values above 2147483647 can be set in the interrupt routine
testval = 0
def test(tim):
global testval
print(str(time.ticks_ms()) + ' Enter testval: ' + str(testval))
testval = testval + 1147483647
print(str(time.ticks_ms()) + ' Exit testval: ' + str(testval))
tim = machine.Timer(-1)
tim.init(period = 2 * 1000, mode = machine.Timer.PERIODIC, callback = test)
Thank you!
Thomas