<s> from threading import Thread , Event <EOL> class PeriodicTask ( Thread ) : <EOL> def __init__ ( self , interval = <NUM_LIT> , target = None ) : <EOL> super ( PeriodicTask , self ) . __init__ ( ) <EOL> self . status = Event ( ) <EOL> self . interval = interval <EOL> self . target = target <EOL> self . daemon = True <EOL> def stop ( self ) : <EOL> self . status . set ( ) <EOL> @ property <EOL> def stopped ( self ) : <EOL> return self . status . isSet ( ) <EOL> def run ( self ) : <EOL> while True : <EOL> if self . stopped : <EOL> return <EOL> self . status . wait ( self . interval ) <EOL> self . task ( ) <EOL> def task ( self ) : <EOL> if not self . target : <EOL> raise NotImplementedError <EOL> self . target ( ) </s>
