#NEWLINE# def _attempt_kill( proc , signal_type , max_try , wait_time ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( not proc . is_running ( ) ) : #NEWLINE# #INDENT# return ( True , 0 ) #NEWLINE# #UNINDENT# #UNINDENT# except psutil . error . NoSuchProcess : #NEWLINE# #INDENT# return ( True , 0 ) #NEWLINE# #UNINDENT# killed = False #NEWLINE# attempts = 0 #NEWLINE# for _i in range ( 0 , max_try ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# LOG . debug ( ( 'Attempting to kill process %s' % proc ) ) #NEWLINE# attempts += 1 #NEWLINE# proc . send_signal ( signal_type ) #NEWLINE# LOG . debug ( ( 'Sleeping for %s seconds before next attempt to kill process %s' % ( wait_time , proc ) ) ) #NEWLINE# sleep ( wait_time ) #NEWLINE# #UNINDENT# except psutil . error . NoSuchProcess : #NEWLINE# #INDENT# killed = True #NEWLINE# break #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# LOG . debug ( 'Failed killing %s due to: %s' , proc , e ) #NEWLINE# LOG . debug ( ( 'Sleeping for %s seconds before next attempt to kill process %s' % ( wait_time , proc ) ) ) #NEWLINE# sleep ( killed ) #NEWLINE# #UNINDENT# #UNINDENT# return ( killed , attempts )