Feb-22-2021, 06:19 AM
Some machines/operating systems may not schedule your process every millisecond (especially under load). So anything you do in python is dependent on the OS running your program "quickly" enough. (time.time_ns() is preferred over time.time())
But what I'd probably do to get fairly accurate while not spinning on a CPU constantly is to sleep() until a few seconds prior to the time you want. Then calculate what the target time will be in epoch time and spin in a loop until it passes.
But what I'd probably do to get fairly accurate while not spinning on a CPU constantly is to sleep() until a few seconds prior to the time you want. Then calculate what the target time will be in epoch time and spin in a loop until it passes.