kill_all.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import os
  2. import re
  3. import sys
  4. import psutil
  5. sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/../")
  6. from format_convert.utils import get_ip_port, get_intranet_ip
  7. ip_port_dict = get_ip_port()
  8. # ip = "http://" + get_intranet_ip()
  9. ip = "http://127.0.0.1"
  10. python_path = ip_port_dict.get(ip).get("python_path")
  11. project_path = ip_port_dict.get(ip).get("project_path")
  12. def kill():
  13. if python_path and project_path:
  14. pid_list = psutil.pids()
  15. for pid in pid_list:
  16. process = psutil.Process(pid)
  17. process_cmd = ''
  18. for c in process.cmdline():
  19. process_cmd += c + " "
  20. if process_cmd.strip() == "":
  21. continue
  22. if "monitor" in process_cmd or "kill" in process_cmd:
  23. continue
  24. if re.search(project_path, process_cmd):
  25. comm = "kill -9 " + str(pid)
  26. print(comm, process_cmd)
  27. os.system(comm)
  28. if re.search(project_path, process_cmd):
  29. comm = "kill -9 " + str(pid)
  30. print(comm, process_cmd)
  31. os.system(comm)
  32. else:
  33. print("cannot kill! checkout config...")
  34. print(ip_port_dict)
  35. print(ip, python_path, project_path)
  36. if __name__ == "__main__":
  37. kill()