<s> """<STR_LIT>""" <EOL> import time <EOL> from datetime import timedelta <EOL> class Timer ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . start_time = self . end_time = None <EOL> def __enter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . start ( ) <EOL> return self <EOL> def __exit__ ( self , exc_type , exc_value , traceback ) : <EOL> """<STR_LIT>""" <EOL> self . stop ( ) <EOL> def start ( self ) : <EOL> """<STR_LIT>""" <EOL> self . start_time = self . _time ( ) <EOL> def stop ( self ) : <EOL> """<STR_LIT>""" <EOL> self . end_time = self . _time ( ) <EOL> @ property <EOL> def elapsed ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . start_time is None : <EOL> return <NUM_LIT:0.0> <EOL> if self . end_time is None : <EOL> return self . _time ( ) - self . start_time <EOL> return self . end_time - self . start_time <EOL> def __str__ ( self ) : <EOL> return str ( timedelta ( seconds = self . elapsed ) ) <EOL> def _time ( self ) : <EOL> """<STR_LIT>""" <EOL> return time . time ( ) <EOL> def run_until_true ( f , timeout ) : <EOL> """<STR_LIT>""" <EOL> with Timer ( ) as t : <EOL> while t . elapsed < timeout : <EOL> if f ( ) : <EOL> return <EOL> time . sleep ( <NUM_LIT> ) <EOL> raise Exception ( "<STR_LIT>" % <EOL> ( timeout , f ) ) </s>
