Commit cce4ba33 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 3d42a2b7
...@@ -106,16 +106,24 @@ def killCommand(pid, log): ...@@ -106,16 +106,24 @@ 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
""" """
try:
process = psutil.Process(pid) process = psutil.Process(pid)
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)])
child_set = None child_set = None
try:
os.kill(pid, signal.SIGSTOP) os.kill(pid, signal.SIGSTOP)
except OSError:
pass
while new_child_set != child_set: while new_child_set != child_set:
child_set = new_child_set child_set = new_child_set
log("killCommand, new_child_set : %r, child_set: %r" % ( log("killCommand, new_child_set : %r, child_set: %r" % (
new_child_set, child_set)) new_child_set, child_set))
for child_pid in child_set: for child_pid in child_set:
try:
os.kill(child_pid, signal.SIGSTOP) os.kill(child_pid, signal.SIGSTOP)
except OSError:
log("killCommand, OSError, %r is already dead" % child_pid)
pass
time.sleep(1) time.sleep(1)
child_set = new_child_set 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)])
...@@ -123,6 +131,9 @@ def killCommand(pid, log): ...@@ -123,6 +131,9 @@ def killCommand(pid, log):
for child_pid in child_set: for child_pid in child_set:
os.kill(child_pid, signal.SIGKILL) os.kill(child_pid, signal.SIGKILL)
os.kill(pid, signal.SIGKILL) os.kill(pid, signal.SIGKILL)
except psutil.NoSuchProcess:
log("killCommand, NoSuchProcess raised")
pass
class ProcessManager(object): class ProcessManager(object):
...@@ -195,9 +206,12 @@ class ProcessManager(object): ...@@ -195,9 +206,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():
try:
if process.username() == user_login and process.name() == name: if process.username() == user_login and process.name() == name:
self.log('ProcesssManager, killall on %s having pid %s' % (name, process.pid)) self.log('ProcesssManager, killall on %s having pid %s' % (name, process.pid))
to_kill_list.append(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