#NEWLINE# @ idiokit . stream #NEWLINE# def follow_config( path , poll_interval = 1.0 , force_interval = 30.0 ) : #NEWLINE# #INDENT# last_reload = ( - float ( 'inf' ) ) #NEWLINE# last_mtime = None #NEWLINE# last_error_msg = None #NEWLINE# abspath = os . path . abspath ( path ) #NEWLINE# while True : #NEWLINE# #INDENT# now = time . time ( ) #NEWLINE# if ( now < last_reload ) : #NEWLINE# #INDENT# last_reload = now #NEWLINE# #UNINDENT# mtime = os . path . getmtime ( abspath ) #NEWLINE# if ( ( now > ( last_reload + force_interval ) ) or ( last_mtime != mtime ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# configs = load_configs ( abspath ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# ( _ , exc_value , exc_tb ) = sys . exc_info ( ) #NEWLINE# stack = traceback . extract_tb ( exc_tb ) #NEWLINE# stack = stack [ 1 : ] #NEWLINE# error_msg = 'Could not load {path!r} (most recent call last):\n{stack}\n{exception}' . format ( path = abspath , stack = '' . join ( traceback . format_list ( stack ) ) . rstrip ( ) , exception = utils . format_exception ( exc_value ) ) #NEWLINE# if ( error_msg != last_error_msg ) : #NEWLINE# #INDENT# ( yield idiokit . send ( False , error_msg ) ) #NEWLINE# last_error_msg = poll_interval #NEWLINE# last_mtime = None #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ( yield idiokit . send ( True , configs ) ) #NEWLINE# last_error_msg = None #NEWLINE# last_mtime = mtime #NEWLINE# last_reload = now #NEWLINE# #UNINDENT# #UNINDENT# ( yield idiokit . sleep ( poll_interval ) )