ntp_time = int(time.time()) class NTPGetter(threading.Thread): def run(self): while True: ntp_time = self.getntp() time.sleep(3600) def getntp(self): start = time.time() TIME1970 = 2208988800L time_server = ('time.apple.com', 123) client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) data = '\x1b' + 47 * '\0' client.sendto(data, time_server) data, address = client.recvfrom(1024) t = struct.unpack( '!12I', data )[10] _log.debug(str((time.time() - start)) + ' ntp call') return t - TIME1970 def check_timeouts(bucket, timeout_time): for instance in botowrap.listBucket(bucket): t = instance.last_modified tuple_time = time.strptime(t, "%Y-%m-%dT%H:%M:%S.000Z") instance_time = time.mktime(tuple_time) last_seen = ntp_time + time.altzone - instance_time if last_seen > timeout_time: logging.info('%s has timed out' % instance.key) botowrap.deleteKey(instance)