#NEWLINE# def kill_all_tasks_in_cgroup( cgroup , kill_process_fn ) : #NEWLINE# #INDENT# tasksFile = os . path . join ( cgroup , 'tasks' ) #NEWLINE# freezer_file = os . path . join ( cgroup , 'freezer.state' ) #NEWLINE# def try_write_to_freezer( content ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# util . write_file ( content , freezer_file ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# i = 0 #NEWLINE# while True : #NEWLINE# #INDENT# i += 1 #NEWLINE# for sig in [ signal . SIGKILL , signal . SIGINT , signal . SIGTERM ] : #NEWLINE# #INDENT# try_write_to_freezer ( 'FROZEN' ) #NEWLINE# with open ( tasksFile , 'rt' ) as tasks : #NEWLINE# #INDENT# task = None #NEWLINE# for task in tasks : #NEWLINE# #INDENT# task = task . strip ( ) #NEWLINE# if ( i > 1 ) : #NEWLINE# #INDENT# logging . warning ( 'Run has left-over process with pid %s in cgroup %s, sending signal %s (try %s).' , task , cgroup , sig , i ) #NEWLINE# #UNINDENT# kill_process_fn ( int ( task ) , sig ) #NEWLINE# #UNINDENT# if ( task is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# #UNINDENT# try_write_to_freezer ( 'THAWED' ) #NEWLINE# time . sleep ( ( i * 0.5 ) )