コード例 #1
0
 def run(self):
     while True:
         self.condition.acquire()
         if len(self.scheduletasks) == 0:
             self.condition.wait();
         else:
             task = self.scheduletasks.pop(0)
             if dates.current_timestamps()>=task.nexttime: 
                 self.threadpool.execute(task.function,*task.args,**task.kwargs)
                 task.nexttime = dates.current_timestamps()+task.period;
             else:
                 self.condition.wait(task.nexttime-dates.current_timestamps())
             self.addtask(task)
         self.condition.release()
コード例 #2
0
 def schedule(self,function,delay=0,period=0,*args,**kwargs):
     curtime = dates.current_timestamps();
     nexttime = curtime+delay
     task = ScheduleTask(nexttime,period,function,*args,**kwargs)
     self.core_thread.addtask(task);
     self.core_thread.condition.acquire()
     self.core_thread.condition.notify_all()
     self.core_thread.condition.release()