def __fire(self): self.__firing = True try: while self.__jobs and self.__jobs[0][0] <= dateandtime.Now(): ts, job, interval = self.__jobs.pop(0) try: job() except: # Hum. import traceback traceback.print_exc() if interval is not None: self.__schedule(job, ts + interval, interval) finally: self.__firing = False if self.__jobs and self.__nextCall is None: dt = self.__jobs[0][0] - dateandtime.Now() nextDuration = int((dt.microseconds + (dt.seconds + dt.days * 24 * 3600) * 10**6) / 10**3) nextDuration = max(nextDuration, 1) nextDuration = min(nextDuration, 2**31-1) from twisted.internet import reactor self.__nextCall = reactor.callLater(1.0 * nextDuration / 1000, self.__callback)
def schedule(self, function, dateTime): proxy = ScheduledMethod(function) def callback(): if proxy in self.__jobs: del self.__jobs[proxy] wx.CallAfter(proxy) if dateTime <= dateandtime.Now() + timedelta.TimeDelta( milliseconds=500): callback() else: self.__jobs[proxy] = job = self.add_date_job(callback, dateTime, misfire_grace_time=0) return job
def schedule_interval(self, function, days=0, minutes=0, seconds=0): proxy = ScheduledMethod(function) def callback(): wx.CallAfter(proxy) if proxy not in self.__jobs: start_date = dateandtime.Now().endOfDay() if days > 0 else None self.__jobs[proxy] = job = self.add_interval_job( callback, days=days, minutes=minutes, seconds=seconds, start_date=start_date, misfire_grace_time=0, coalesce=True) return job
def scheduleInterval(self, job, interval, startDateTime=None): self.__schedule(job, startDateTime or dateandtime.Now() + interval, interval)
def schedule_interval(self, function, days=0, minutes=0, seconds=0): job = ScheduledMethod(function) if not self.__scheduler.isScheduled(job): startDate = dateandtime.Now().endOfDay() if days > 0 else None self.__scheduler.scheduleInterval(job, timedelta.TimeDelta(days=days, minutes=minutes, seconds=seconds), startDateTime=startDate) return job
def __finished_recurring(self): ''' Return whether this recurrence is finished, either because the maximum number of recurrences has happened or because the end date for the reccurences has passed. ''' return self.max != 0 and self.count >= self.max or \ date.Now() > self.stop_datetime