-
Notifications
You must be signed in to change notification settings - Fork 165
Timer.Alarm does not immediately update free timer count after alarm.callback(None) #111
Comments
I realized after doing some more testing with a friend that I needed to be calling Timer.Alarm.cancel() instead of Timer.Alarm.callback(None). This page in the documentation seems unclear about how to properly disregard a Timer you're no longer interested in. Am I missing something? Could I submit a documentation patch somehow? |
Sorry, here's the docs page I was talking about: https://docs.pycom.io/chapter/tutorials/all/timers.html |
@rkeiii That's right. It used to be, that Timer.Alarm.callback(None) would remove the alarm. But now it just re-enables the alarm. The section of interest is int mods/machtimer_alarm.c, line 237. replacing line 238 by
could do the trick. Or the documentation can be updated. |
@robert-hh I'm quite new to Micropython as a whole so I'd be open to suggestion on whichever approach would be better. My gut tells me completely cancelling the Timer.Alarm as a result of calling Timer.Alarm.callback(None) might be somewhat non-intuitive behavior. What if I want to re-use the Timer.Alarm with a new callback? So I think I would probably lean toward improving the documentation but like I say I'm no authority on the matter. Would you happen to know if it's possible/where to submit a documentation patch? |
@rkeiii Since the timer has only the noticeable reaction of calling a callback, Timer.Alarm.callback(None) is practically the same as Timer.Alarm.cancel(). There is not need to let the timer running if there is nothing to do. |
Hello, Thanks for reporting this. Cheers, |
The fix is actually to change line 259 of machtimer_alarm.c to: } else if (self->handler != mp_const_none) { This is done in master now. Will be available with the next release. |
@danicampora Thank you for the fix. |
Update pyexec.c
Please include the following information when submitting a bug report:
Here's the "timer code" that I'm using the instantiate the Timer.Alarm's and also to free them with alarm.callback(None).
Here's an example run of my code. You can see from the logging my code has it's own list it uses to track active timers which does not match up with how many the Timer.Alarm code things are free.
The text was updated successfully, but these errors were encountered: