Running tasks at intervals

Sometimes we want to run a task every few minutes, or expire sessions after 15 minutes, or other events that are generated based on time. We do this using objects that conform to the Delayed interface (see twisted.python.delay).

A delayed must define two functions:

For example:
class OnceAMinute:
    """Runs once a minute."""
    
    def timeout(self):
        return 60.0
    
    def runUntilCurrent(self):
        print "a minute has passed"

# register the Delayed object with the Twisted event loop:
o = OnceAMinute()
from twisted.internet import main
main.addDelayed(o)