Commit 5663aec7 authored by Sebastien Robin's avatar Sebastien Robin Committed by Klaus Wölfel

erp5testnode: a process might be already dead right before we try to kill it

Since a process might exit by himself at any time, handle exceptions when
we try kill processes
parent 09bdcb6e
...@@ -106,23 +106,34 @@ def killCommand(pid, log): ...@@ -106,23 +106,34 @@ def killCommand(pid, log):
child (until childs does not change) and then we brutally kill child (until childs does not change) and then we brutally kill
everyone at the same time everyone at the same time
""" """
process = psutil.Process(pid) try:
new_child_set = set([x.pid for x in process.children(recursive=True)]) process = psutil.Process(pid)
child_set = None
os.kill(pid, signal.SIGSTOP)
while new_child_set != child_set:
child_set = new_child_set
log("killCommand, new_child_set : %r, child_set: %r" % (
new_child_set, child_set))
for child_pid in child_set:
os.kill(child_pid, signal.SIGSTOP)
time.sleep(1)
child_set = new_child_set
new_child_set = set([x.pid for x in process.children(recursive=True)]) new_child_set = set([x.pid for x in process.children(recursive=True)])
log("killCommand, finishing, child_set : %r" % (child_set,)) child_set = None
for child_pid in child_set: try:
os.kill(child_pid, signal.SIGKILL) os.kill(pid, signal.SIGSTOP)
os.kill(pid, signal.SIGKILL) except OSError:
pass
while new_child_set != child_set:
child_set = new_child_set
log("killCommand, new_child_set : %r, child_set: %r" % (
new_child_set, child_set))
for child_pid in child_set:
try:
os.kill(child_pid, signal.SIGSTOP)
except OSError:
log("killCommand, OSError, %r is already dead" % child_pid)
pass
time.sleep(1)
child_set = new_child_set
new_child_set = set([x.pid for x in process.children(recursive=True)])
log("killCommand, finishing, child_set : %r" % (child_set,))
for child_pid in child_set:
os.kill(child_pid, signal.SIGKILL)
os.kill(pid, signal.SIGKILL)
except psutil.NoSuchProcess:
log("killCommand, NoSuchProcess raised")
pass
class ProcessManager(object): class ProcessManager(object):
...@@ -196,9 +207,12 @@ class ProcessManager(object): ...@@ -196,9 +207,12 @@ class ProcessManager(object):
user_login = getpass.getuser() user_login = getpass.getuser()
to_kill_list = [] to_kill_list = []
for process in psutil.process_iter(): for process in psutil.process_iter():
if process.username() == user_login and process.name() == name: try:
self.log('ProcesssManager, killall on %s having pid %s' % (name, process.pid)) if process.username() == user_login and process.name() == name:
to_kill_list.append(process.pid) self.log('ProcesssManager, killall on %s having pid %s' % (name, process.pid))
to_kill_list.append(process.pid)
except psutil.NoSuchProcess:
pass
for pid in to_kill_list: for pid in to_kill_list:
killCommand(pid, self.log) killCommand(pid, self.log)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment