import tempfile
import sys
import subprocess
+import time
class outRedirection():
'''redirection of standart output
def check_proc_existence_and_kill(regex):
cmd = 'ps aux | grep "' + regex + '"'
- psRes = subprocess.check_output(cmd, shell=True)
+ 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:
pid = line2[1]
kill9(pid)
return pid
- return 0
\ No newline at end of file
+ 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