Show
Ignore:
Timestamp:
07/25/07 10:47:36 (1 year ago)
Author:
carndt
Message:

Ran reindent.py on all .py files to remove extra line-ending space and add NL at eof

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/turbogears/scheduler.py

    r1496 r3366  
    1717There are three Scheduler classes: 
    1818    Scheduler    ThreadedScheduler    ForkedScheduler 
    19      
     19 
    2020You usually add new tasks to a scheduler using the add_interval_task or 
    2121add_daytime_task methods, with the appropriate processmethod argument 
     
    5858        self.running=True 
    5959        self.sched = sched.scheduler(time.time, self.__delayfunc) 
    60   
     60 
    6161    def __delayfunc(self, delay): 
    6262        # This delay function is basically a time.sleep() that is 
     
    7979            if endtime > now: 
    8080                time.sleep(endtime - now) 
    81   
     81 
    8282    def _acquire_lock(self):    pass 
    8383    def _release_lock(self):    pass 
    84         
     84 
    8585    def add_interval_task(self, action, taskname, initialdelay, interval, processmethod, args, kw): 
    8686        """Add a new Interval Task to the schedule. A very short initialdelay or one of 
     
    152152            task.event = self.sched.enter(delay, 0, task, 
    153153                        (weakref.ref(self),) ) 
    154                          
     154 
    155155    def schedule_task_abs(self, task, abstime): 
    156156        """Low-level method to add a new task to the scheduler for the given absolute time value.""" 
     
    165165            task.event = self.sched.enterabs(abstime, 0, task, 
    166166                                (weakref.ref(self),) ) 
    167              
     167 
    168168 
    169169    def start(self): 
    170170        """Start the scheduler.""" 
    171171        self._run() 
    172          
     172 
    173173    def stop(self): 
    174174        """Remove all pending tasks and stop the Scheduler.""" 
    175175        self.running=False 
    176176        self.sched.queue[:]=[] 
    177      
     177 
    178178    def cancel(self, task): 
    179179        self.sched.cancel(task.event) 
     
    201201        self.args=args 
    202202        self.kw=kw 
    203          
     203 
    204204    def __call__(self, schedulerref): 
    205205        """Execute the task action in the scheduler's thread.""" 
     
    209209            self.handle_exception(x) 
    210210        self.reschedule(schedulerref()) 
    211          
     211 
    212212    def reschedule(self, scheduler): 
    213213        """This is an abstract class, this method is defined in one of the sub classes!""" 
    214214        raise NotImplementedError("you're using the abstract base class 'Task', use a concrete class instead") 
    215          
     215 
    216216    def execute(self): 
    217217        """Execute the actual task.""" 
    218218        self.action(*self.args, **self.kw) 
    219          
     219 
    220220    def handle_exception(self, exc): 
    221221        """Handle any exception that occured during task execution.""" 
     
    230230        Task.__init__(self, name, action, args, kw) 
    231231        self.interval=interval 
    232          
     232 
    233233    def reschedule(self, scheduler): 
    234234        # reschedule this task according to its interval (in seconds). 
     
    241241    def __init__(self, timeonday): 
    242242        self.timeonday=timeonday 
    243          
     243 
    244244    def get_schedule_time(self, today): 
    245245        """Calculate the time value at which this task is to be scheduled.""" 
     
    254254        now[5]=0 # seconds 
    255255        return time.mktime(now) 
    256          
     256 
    257257    def reschedule(self, scheduler): 
    258258        # Reschedule this task according to the daytime for the task. 
     
    274274        Task.__init__(self, name, action, args, kw) 
    275275        self.days=weekdays 
    276          
     276 
    277277    def execute(self): 
    278278        # This is called every day, at the correct time. We only need to 
     
    281281        if weekday in self.days: 
    282282            self.action(*self.args, **self.kw) 
    283          
     283 
    284284class MonthdayTask(DayTaskRescheduler, Task): 
    285285    """A task that is called at specific days in a month (1-31), at a fixed time on the day.""" 
     
    292292        Task.__init__(self, name, action, args, kw) 
    293293        self.days=monthdays 
    294          
     294 
    295295    def execute(self): 
    296296        # This is called every day, at the correct time. We only need to 
     
    302302try: 
    303303    import threading 
    304      
     304 
    305305    class ThreadedScheduler(Scheduler): 
    306306        """A Scheduler that runs in its own thread.""" 
     
    356356if hasattr(os,"fork"): 
    357357    import signal 
    358      
     358 
    359359    class ForkedScheduler(Scheduler): 
    360360        """A Scheduler that runs in its own forked process.""" 
     
    430430        initialdelay=0, processmethod=method.threaded, taskname=None): 
    431431    si = _get_scheduler() 
    432     return si.add_interval_task(action=action, interval=interval, args=args,  
     432    return si.add_interval_task(action=action, interval=interval, args=args, 
    433433            kw=kw, initialdelay=initialdelay, 
    434434            processmethod=processmethod, taskname=taskname) 
    435435 
    436 def add_weekday_task(action, weekdays, timeonday, args=None, kw=None,  
     436def add_weekday_task(action, weekdays, timeonday, args=None, kw=None, 
    437437        processmethod=method.threaded, taskname=None): 
    438438    si = _get_scheduler() 
    439439    return si.add_daytime_task(action=action, taskname=taskname, 
    440             weekdays=weekdays, monthdays=None, timeonday=timeonday,  
     440            weekdays=weekdays, monthdays=None, timeonday=timeonday, 
    441441            processmethod=processmethod, args=args, kw=kw) 
    442      
    443      
    444 def add_monthday_task(action, monthdays, timeonday,  
    445         args=None, kw=None,  
     442 
     443 
     444def add_monthday_task(action, monthdays, timeonday, 
     445        args=None, kw=None, 
    446446        processmethod=method.threaded, taskname=None): 
    447447    si = _get_scheduler() 
    448448    return si.add_daytime_task(action=action, taskname=taskname, 
    449             weekdays=None, monthdays=monthdays, timeonday=timeonday,  
     449            weekdays=None, monthdays=monthdays, timeonday=timeonday, 
    450450            processmethod=processmethod, args=args, kw=kw) 
    451451