<s> from twisted . internet import reactor <EOL> from twisted . internet . task import LoopingCall <EOL> class Tasks ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _tasks = [ ] <EOL> def add_loop ( self , time , callback , * args ) : <EOL> task = LoopingCall ( callback , * args ) <EOL> task . start ( time , now = False ) <EOL> self . _tasks . append ( task ) <EOL> return task <EOL> def add_delay ( self , time , callback , * args ) : <EOL> task = reactor . callLater ( time , callback , * args ) <EOL> def stop ( ) : <EOL> if task . active ( ) : <EOL> task . cancel ( ) <EOL> def restart ( ) : <EOL> if task . active ( ) : <EOL> task . reset ( time ) <EOL> task . restart = restart <EOL> task . stop = stop <EOL> self . _tasks . append ( task ) <EOL> return task <EOL> def stop_all ( self ) : <EOL> while len ( self . _tasks ) > <NUM_LIT:0> : <EOL> task = self . _tasks . pop ( <NUM_LIT:0> ) <EOL> task . stop ( ) </s>
