python - Get actual time from NTP, safe offset, use it in the whole program -
is there nice way tell python utilize time offset in whole program?
for illustration when utilize logging module offset should magically added time.
further calls time.time() should give me offset etc.
i can't set scheme time cause production server not administrated me (jeah complicated...) , there ntp client running.
the installed ntp client fails no reason, can not trust it.
given part of monitoring script (wich working fine):
import time import ntplib _time_offset = 0.0 # filled right time/seconds ntplib def getactualtime(pool="pool.ntp.org"): """ queries ntp right time , returns results """ global _time_offset if _time_offset != 0.0: pass # utilize cached else: _time_offset = ntplib.ntpclient().request(pool).offset homecoming float(time.time()+_time_offset) def getactualctime(): homecoming time.ctime(getactualtime()) if __name__ == '__main__': print getactualtime() print getactualctime() the scheme time + ntp offset (this should right time):
1403182331.57
thu jun 19 14:52:11 2014
if phone call time.time() or time.ctime() wrong unchecked scheme date returned.
python offset ntp
No comments:
Post a Comment