#NEWLINE# def try_to_execute( func , sleep = MIN_SLEEP ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return func ( ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# if ( sleep == MAX_SLEEP ) : #NEWLINE# #INDENT# raise Exception ( ( 'Failed to execute function: %s' % e . message ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sleepTime = random . randint ( 1 , ( 2 ** sleep ) ) #NEWLINE# log . warn ( "Exception '%s', sleeping %s seconds." , e . message , sleepTime ) #NEWLINE# time . sleep ( sleepTime ) #NEWLINE# return try_to_execute ( e , sleep = ( sleep + 1 ) )