def start(period=1.0, *args): global should_run if not should_run: should_run = 1 first_time = math.floor(time.time()) + period scheduler.at(first_time, absolute_callback, (period,first_time,)) scheduler.after(first_time-time.time(), relative_callback, (period,first_time,)) return
def absolute_callback(period,*args): global should_run this_time = time.time() if should_run: next_time = math.floor(time.time()) + period scheduler.at(next_time, absolute_callback, (period,next_time,)) print 'A: %s %s' % (this_time, args) else: print 'A: %s %s - STOPPED' % (this_time, args) return
def set_timeout(self, timeout): super(FaultEvent, self).set_timeout(timeout) self.timeoutevent = FaultTimedOut(self, self.closetime, self.source, None, self.origin, None) self.scheduled_timeout = scheduler.at(self.closetime, self.handle_event, (self.timeoutevent, ))
def go(self): if self._scheduled is not None and self.scheduled_time() > time.time(): # The drifting clock has done us in... self._scheduled = scheduler.at(self.scheduled_time(), self.go, ()) return thread = threading.Thread(name=self.log.name, target=self.collect,args=()) thread.start()
def override(self, value, seconds = None, *clearing_value): if len(clearing_value): self.set_clearing_value(clearing_value[0]) self.__state_lock.acquire() try: self.__override = override = UUID() self.__overridden_at = time.time() self.__clears_at = None self.node.set(value) self.active_overrides.setdefault(self.node.url, self) if seconds is not None: self.__clears_at = self.__overridden_at + seconds scheduler.at(self.__clears_at, self.clear_override, (override,)) finally: self.__state_lock.release() self.__notify_if_changed() return override
def override(self, value, seconds=None, *clearing_value): if len(clearing_value): self.set_clearing_value(clearing_value[0]) self.__state_lock.acquire() try: self.__override = override = UUID() self.__overridden_at = time.time() self.__clears_at = None self.node.set(value) self.active_overrides.setdefault(self.node.url, self) if seconds is not None: self.__clears_at = self.__overridden_at + seconds scheduler.at(self.__clears_at, self.clear_override, (override, )) finally: self.__state_lock.release() self.__notify_if_changed() return override
def schedule_subscription(self, subscription, timestamp): self.scheduling_lock.acquire() try: schedulegroup = self.execution_groups.get(timestamp) if schedulegroup is None: schedulegroup = SubscriptionGroup(self, timestamp) self.execution_groups[timestamp] = schedulegroup schedulegroup.scheduled = scheduler.at(timestamp, schedulegroup.execute) schedentry = schedulegroup.add_subscription(subscription) finally: self.scheduling_lock.release() return schedentry
def schedule_subscription(self, subscription, timestamp): self.scheduling_lock.acquire() try: schedulegroup = self.execution_groups.get(timestamp) if schedulegroup is None: schedulegroup = SubscriptionGroup(self, timestamp) self.execution_groups[timestamp] = schedulegroup schedulegroup.scheduled = scheduler.at( timestamp, schedulegroup.execute) schedentry = schedulegroup.add_subscription(subscription) finally: self.scheduling_lock.release() return schedentry
def _schedule(self): next = self.next_time() self._scheduled = scheduler.at(next, self.go, (next,))
def setup_subscr_timer(self): self._scan_scheduled = scheduler.at(self.next_scan_time(), self.scan, ())
def _schedule(self): if self.period == 0: self._scheduled = None return self._scheduled = scheduler.at(self.next_scheduled_time(),self.go,())
def _schedule_toggle(self): when = time.time() + self.device.toggle_period self._scheduled = scheduler.at(when, self._toggle_state, ()) return
def _schedule_refresh(self): scheduler.at(self._next_time(), self._refresh)
def set_timeout(self, timeout): super(FaultEvent, self).set_timeout(timeout) self.timeoutevent = FaultTimedOut( self, self.closetime, self.source, None, self.origin, None) self.scheduled_timeout = scheduler.at( self.closetime, self.handle_event, (self.timeoutevent,))
def _schedule(self): next = self.next_time() self._scheduled = scheduler.at(next, self.go, (next, ))