X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=test%2F_testTools%2Ftools.py;h=2930b99601f8fb1bfe8a044c80bde19328808ac1;hb=5878e27c0081e371307cb7b7d9d72322c112bf2d;hp=daf88a7204239aeb3ed6925a1167a82c5e7d25bc;hpb=c3f03fb1a8d8a5a20baef855572c2e999433ff13;p=tools%2Fsat.git diff --git a/test/_testTools/tools.py b/test/_testTools/tools.py index daf88a7..2930b99 100644 --- a/test/_testTools/tools.py +++ b/test/_testTools/tools.py @@ -19,6 +19,7 @@ import tempfile import sys import subprocess +import time class outRedirection(): '''redirection of standart output @@ -47,8 +48,30 @@ class outRedirection(): except Exception as exc: print('Problem with redirection : %s' % exc) sys.exit(1) - -def check_proc_existence(cmd, text_to_find): - - p = subprocess.Popen(cmd, shell=True) - p.communicate() \ No newline at end of file + +def kill9(pid): + subprocess.call("kill -9 " + pid, shell=True) + +def check_proc_existence_and_kill(regex): + cmd = 'ps aux | grep "' + regex + '"' + psRes = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).communicate()[0] + psRes = psRes.split('\n') + for line in psRes: + if 'grep' in line or len(line) == 0: + continue + line2 = [i for i in line.split(' ') if i != ''] + pid = line2[1] + kill9(pid) + return pid + return 0 + +def check_proc_existence_and_kill_multi(regex, nb_kills, time_between_two_checks = 1): + found = False + i = 0 + while not found and i < nb_kills : + found = check_proc_existence_and_kill(regex) + if found: + return found + time.sleep(time_between_two_checks) + i+=1 + return 0 \ No newline at end of file