From fe82b501e050d4f273371eba4ce36b7b87a9c3bc Mon Sep 17 00:00:00 2001 From: Qiyuan Gong Date: Sat, 12 Sep 2020 22:02:55 +0800 Subject: [PATCH] Hotfix for ray psutil on macOS (#2856) * Fix psutil test fail on macOS. * Add exception handle for running without root. --- python/orca/src/bigdl/orca/ray/raycontext.py | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/python/orca/src/bigdl/orca/ray/raycontext.py b/python/orca/src/bigdl/orca/ray/raycontext.py index b28944eadc4..1b7e8a688fd 100755 --- a/python/orca/src/bigdl/orca/ray/raycontext.py +++ b/python/orca/src/bigdl/orca/ray/raycontext.py @@ -63,11 +63,22 @@ def kill_redundant_log_monitors(redis_address): import subprocess log_monitor_processes = [] for proc in psutil.process_iter(["name", "cmdline"]): - cmdline = subprocess.list2cmdline(proc.cmdline()) - is_log_monitor = "log_monitor.py" in cmdline - is_same_redis = "--redis-address={}".format(redis_address) - if is_log_monitor and is_same_redis in cmdline: - log_monitor_processes.append(proc) + try: + # Avoid throw exception when listing lwsslauncher in macOS + if proc.name() is None or proc.name() == "lwsslauncher": + continue + cmdline = subprocess.list2cmdline(proc.cmdline()) + is_log_monitor = "log_monitor.py" in cmdline + is_same_redis = "--redis-address={}".format(redis_address) + if is_log_monitor and is_same_redis in cmdline: + log_monitor_processes.append(proc) + except psutil.AccessDenied: + # psutil may encounter AccessDenied exceptions + # when it's trying to visit core services + if psutil.MACOS: + continue + else: + raise if len(log_monitor_processes) > 1: for proc in log_monitor_processes[1:]: