commit 3e5ce99e82dcab619d1b0412b5117545ae4f7017
parent c10ade711dd75918ed5accd249da37c4bc3d6785
Author: James Prestwood <prestwoj@gmail.com>
Date: Fri, 24 Jun 2022 16:07:35 -0700
test-runner: make is_process_running more accurate
This function was checking if the process object exists, which can
persist long after a process is killed, or dies unexpectedly. Check
that the actual PID exists by sending signal 0.
Diffstat:
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/tools/utils.py b/tools/utils.py
@@ -342,10 +342,24 @@ class Namespace:
def stop_process(self, p, force=False):
p.kill(force)
+ def _is_running(self, pid):
+ try:
+ os.kill(pid, 0)
+ except OSError:
+ return False
+
+ return True
+
def is_process_running(self, process):
for p in Process.get_all():
- if p.namespace == self.name and p.args[0] == process:
- return True
+ # Namespace processes are actually started by 'ip' where
+ # the actual process name is at index 4 of the arguments.
+ idx = 0 if not p.namespace else 4
+
+ if p.namespace == self.name and p.args[idx] == process:
+ # The process object exists, but make sure its
+ # actually running.
+ return self._is_running(p.pid)
return False
def _cleanup_dbus(self):