import os import re import sys import psutil sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../") from format_convert.utils import get_ip_port, get_intranet_ip ip_port_dict = get_ip_port() ip = "http://127.0.0.1" python_path = ip_port_dict.get(ip).get("MASTER").get("python_path") gunicorn_path = ip_port_dict.get(ip).get("MASTER").get("gunicorn_path") project_path = ip_port_dict.get(ip).get("MASTER").get("project_path") def kill(): if python_path and project_path: pid_list = psutil.pids() for pid in pid_list: process = psutil.Process(pid) process_cmd = '' for c in process.cmdline(): process_cmd += c + " " if process_cmd.strip() == "": continue if "monitor" in process_cmd or "kill" in process_cmd: continue if re.search(project_path, process_cmd): comm = "kill -9 " + str(pid) print(comm, process_cmd) os.system(comm) else: print("cannot kill! checkout config...") print(ip_port_dict) print(ip, python_path, project_path) if __name__ == "__main__": kill()