[Twisted-Python] Re-Occuring Operations
    Clark C. Evans 
    cce at clarkevans.com
       
    Sun Mar 16 23:42:17 MST 2003
    
    
  
Hello.   I was wondering if there is anything which handles 
re-occuring functions; that is, an auto-rescheduler or
something of that nature.   Here is what I came up with,
I'm sure there is a shorter 'lambda' form, but I was
going for clarity here.
  class MultiRun:
      """ apply a callable while it returns true """
      def __init__(self, callable, waitInterval = 0):
          self.callable = callable
          self.waitInterval = waitInterval
          self.iterate(starting = 1)
      def iterate(self, starting = 0):
          if starting or self.callable():
              from twisted.internet import reactor
              reactor.callLater(self.waitInterval, self.iterate)
Something like this would be useful, it's already emerged in
two different contexts in my code:
   (a) a background operation (which never returns true)
       that runs every 5 minutes, 
   (b) an operation which keeps pooling a resource, if 
       the resource is busy it returns true, otherwise 
       it processes the resource and returns false to
       signal that it is done
Perhaps calling this an "Operation" would be good.
Best,
clark
    
    
More information about the Twisted-Python
mailing list