View Single Post
daperl's Avatar
Posts: 2,427 | Thanked: 2,986 times | Joined on Dec 2007
#101
Originally Posted by danramos View Post
Rather than sleeping as a way of freeing up CPU cycles and checking every minute (I'd also immediately considered drifting and imprecision as issues if this is implemented), is there a way to use a system interrupt based library to run the update code every time the system's clock has incremented the minute? I'm not familiar with programming in python, but I would assume this would mean using a library that deals with the HAL (Hardware Abstraction Layer) interface? This would offload the work from the app and leave it up to the operating system to run the routine as an event.
Syncing in user space should be simple. The following psuedo code would cost very little and makes the reasonable assumption that sleeping will take no less than 60 seconds and no more than a 120 seconds.

Code:
def clock_update():
  while not_done:
    now = get_system_time_in_seconds()
    update_clock (now)
    sleep_time = 60 - now MOD 60
    sleep_for_seconds (sleep_time)

clock_update_thread = threading.Thread (target=clock_update)
clock_update_thread.start()
__________________
N9: Go white or go home
 

The Following 2 Users Say Thank You to daperl For This Useful Post: