4

I have a server application that needs to schedule functions to be called at various times during the week, with a desired accuracy of plus or minus 15 seconds, let's say. threading.Timer is the simplest solution, but I'm concerned about accuracy when using intervals of several hundred thousand seconds. Everything I can find concerning Timer's accuracy focuses on timers with comparatively tiny periods.

Tests using timers with intervals on the order of an hour or two yield almost perfect results, but I'd like some assurance this is something I can rely on.

Rob
  • 75
  • 1
  • 4

1 Answers1

1

Accuracy should match the computer clock: milliseconds.

The real problem is the jobs you're running. Do they finish before the period expires? That's dependent on the job and the machine load. The Timer can't help with that.

duffymo
  • 305,152
  • 44
  • 369
  • 561
  • 1
    It seems too optimistic. I doubt that even the computer clock itself (without ntp adjustments or other means of synchronization with authoritative time sources) can be accurate within milliseconds over period of several days: [*"It is not unusual for an RTC to gain or lose several seconds or even minutes a day, and some of them -- while still considered to be operating correctly by the manufacturer-- can be off by an hour or more after a week or two without correction."*](http://blog.codinghorror.com/keeping-time-on-the-pc/) – jfs Jun 04 '15 at 20:06
  • Sorry, I call bullsh*t on this one. No machine I've ever used, at home or at work, has ever been off by hours. Never. If there's correction going on to maintain it, I'm not aware of it. Built into the OS. – duffymo Jun 05 '15 at 12:34
  • @duffymo So admit you are ignorant but still calling it bullshit. :-) Hardware RTC ≠ the time calculated by the operating system. Operating systems usually _do_ corrections because most hardware RTCs _do_ lose or gain time. It seems to be simpler/cheaper to use RTCs with a constant but slightly off clock speed corrected with software than to use more precisely calibrated RTCs. – BlackJack Jun 16 '15 at 14:31
  • So it appears that the adjustments are working and batch jobs won't be off by much - like I said. "Hoist by your own petard" comes to mind. – duffymo Jun 21 '15 at 01:24