Python Forum
waking up every second - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: waking up every second (/thread-17500.html)



waking up every second - Skaperen - Apr-13-2019

if you write some code to wake up every second, it could accumulate the system delays and quickly be way off. what have you done to deal with this? back in my days of C programming, my code would calculate how long to wait, such as in nanoseconds. doing so in Python seems to work. is there a better way to do this in Python?


RE: waking up every second - Larz60+ - Apr-13-2019

You should use event processing to create an event (interrupt) when something (whatever you decide) triggers.
I hate to point to stack overflow, but there are two posts there of interest:
https://stackoverflow.com/questions/1092531/event-system-in-python
https://stackoverflow.com/a/1096614


RE: waking up every second - Skaperen - Apr-13-2019

the publish-subscribe pattern make sense and seems right. now to look through the choices and make sure they have reliable time-cycle publishers. time-cycle could be complex because so many cycle periods are possible, such as "every 35 seconds".


RE: waking up every second - Larz60+ - Apr-14-2019

I always felt that all computer motherboards should have three items available for programming use:
An A/D converter, A D/A converter, and a good counter timer independent of main clock.


RE: waking up every second - Skaperen - Apr-14-2019

and the counter-timer should have a way to set a level-state interrupt.