<s> """<STR_LIT>""" <EOL> from threading import Thread , Event <EOL> class PeriodicTimer ( Thread ) : <EOL> def __init__ ( self , interval , function , * args , ** kwargs ) : <EOL> Thread . __init__ ( self ) <EOL> self . daemon = True <EOL> assert interval > <NUM_LIT:0> <EOL> self . interval = interval <EOL> assert function <EOL> self . function = function <EOL> self . args = args <EOL> self . kwargs = kwargs <EOL> self . finished = Event ( ) <EOL> def _is_alive ( self ) : <EOL> return ( <EOL> bool ( self . finished ) and <EOL> bool ( self . interval ) and <EOL> bool ( self . function ) <EOL> ) <EOL> def end ( self ) : <EOL> if self . _is_alive ( ) : <EOL> self . finished . set ( ) <EOL> def run ( self ) : <EOL> while True : <EOL> if not self . _is_alive ( ) or self . finished . isSet ( ) : <EOL> break <EOL> self . finished . wait ( self . interval ) <EOL> self . function ( * self . args , ** self . kwargs ) </s>
