Browse Source

add try-catch in kill_all.py

fangjiasheng 2 years ago
parent
commit
97508bb318
1 changed files with 6 additions and 5 deletions
  1. 6 5
      format_convert/kill_all.py

+ 6 - 5
format_convert/kill_all.py

@@ -20,7 +20,10 @@ def kill():
     if python_path and project_path:
         pid_list = psutil.pids()
         for pid in pid_list:
-            process = psutil.Process(pid)
+            try:
+                process = psutil.Process(pid)
+            except:
+                continue
             process_cmd = ''
             for c in process.cmdline():
                 process_cmd += c + " "
@@ -32,10 +35,8 @@ def kill():
             if re.search(project_path, process_cmd):
                 comm = "kill -9 " + str(pid)
                 print(comm, process_cmd)
-                try:
-                    os.system(comm)
-                except:
-                    continue
+                os.system(comm)
+
     else:
         print("cannot kill! checkout config...")
         print(ip_port_dict)