#NEWLINE# def start( self , interval , initial_delay = None ) : #NEWLINE# #INDENT# self . _running = True #NEWLINE# done = event . Event ( ) #NEWLINE# def _inner( ) : #NEWLINE# #INDENT# if initial_delay : #NEWLINE# #INDENT# greenthread . sleep ( initial_delay ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# while self . _running : #NEWLINE# #INDENT# start = timeutils . utcnow ( ) #NEWLINE# self . f ( * self . args , ** self . kw ) #NEWLINE# end = timeutils . utcnow ( ) #NEWLINE# if ( not self . _running ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# delay = ( interval - timeutils . delta_seconds ( start , end ) ) #NEWLINE# if ( delay <= 0 ) : #NEWLINE# #INDENT# LOG . warning ( _LW ( 'task run outlasted interval by %s sec' ) , ( - delay ) ) #NEWLINE# #UNINDENT# greenthread . sleep ( ( delay if ( delay > 0 ) else 0 ) ) #NEWLINE# #UNINDENT# #UNINDENT# except LoopingCallDone as e : #NEWLINE# #INDENT# self . stop ( ) #NEWLINE# done . send ( e . retvalue ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# LOG . exception ( _LE ( 'in fixed duration looping call' ) ) #NEWLINE# done . send_exception ( * sys . exc_info ( ) ) #NEWLINE# return #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# done . send ( True ) #NEWLINE# #UNINDENT# #UNINDENT# self . done = done #NEWLINE# greenthread . spawn_n ( _inner ) #NEWLINE# return initial_delay . done