Contact: fumanchu@aminus.org

Log in as guest/misc to create tickets

Changeset 105

Show
Ignore:
Timestamp:
08/16/06 09:36:51
Author:
dowski
Message:

A couple changes to make Workers and Schedulers more robust.

1. Worker.advance() now correctly handles self.recurrence == None.
2. Scheduler.stop() now correctly handles self.curthread == None

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • recur.py

    r104 r105  
    792792        If the recurrence series is exhausted, self.nextrun will be None. 
    793793        """ 
     794        if not self.recurrence: 
     795            self.nextrun = None 
     796            return 
     797         
    794798        try: 
    795799            next = self.recurrence.next() 
     
    896900    def stop(self): 
    897901        self.terminated = True 
    898         self.curthread.cancel() 
     902        if self.curthread: 
     903            self.curthread.cancel() 
    899904        for w in self.workers.values(): 
    900905            w.stop() 
  • test_recur.py

    r103 r105  
    446446                recur.Worker.__init__(self, *args, **params) 
    447447                self.active = False 
    448  
     448             
    449449            def work(self): 
    450450                # This worker starts paused (inactive) and shouldn't do 
    451451                # any work 
    452452                paused[0] += 1 
     453         
     454        # the aptly named... 
     455        class WorkerNotAppearingInThisFilm(recur.Worker): 
     456            def work(self): 
     457                pass 
    453458         
    454459        s = recur.Scheduler({'mycounter': Counter("1 second")}) 
     
    461466        s = recur.Scheduler({'c1': Counter("1 second"), 
    462467                             'c2': AnotherCounter("2 seconds"), 
    463                              'c3': PausedWorker("1 second")}) 
     468                             # A worker that starts paused (inactive). 
     469                             'c3': PausedWorker("1 second"), 
     470                             # A worker with an empty recurrence string. 
     471                             # This is allowed in __init__, and sets 
     472                             # self.recurrence to None. 
     473                             'c4': WorkerNotAppearingInThisFilm("")}) 
    464474        s.start() 
    465475        try: 
     
    503513        finally: 
    504514            s.stop() 
    505  
     515         
     516        # Test a Scheduler with a single Worker with an empty recurrence string 
     517        s = recur.Scheduler({'w': WorkerNotAppearingInThisFilm("")}) 
     518        s.start() 
     519        time.sleep(0.5) 
     520        s.stop() 
    506521 
    507522if __name__ == "__main__":