MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / _get_pid_by_command

Method _get_pid_by_command

class/projectModel/pythonModel.py:1162–1229  ·  view source on GitHub ↗
(self, project_data: dict)

Source from the content-addressed store, hash-verified

1160 return s_mgr.other_service_pids()
1161
1162 def _get_pid_by_command(self, project_data: dict) -> Optional[int]:
1163 project_config = project_data["project_config"]
1164 v_path = project_config['vpath']
1165 runfile = project_config['rfile']
1166 path = project_config['path']
1167 stype = project_config["stype"]
1168 pids = []
1169 try:
1170 if stype == "python":
1171 for i in psutil.process_iter(['pid', 'exe', 'cmdline']):
1172 try:
1173 if i.status() == "zombie":
1174 continue
1175 if v_path in i.exe() and runfile in " ".join(i.cmdline()):
1176 pids.append(i.pid)
1177 except:
1178 pass
1179
1180 elif stype in ("uwsgi", "gunicorn"):
1181 for i in psutil.process_iter(['pid', 'exe', 'cmdline']):
1182 try:
1183 if i.status() == "zombie":
1184 continue
1185 if v_path in i.exe() and stype in i.exe() and \
1186 path in " ".join(i.cmdline()) and stype in " ".join(i.cmdline()):
1187 pids.append(i.pid)
1188 except:
1189 pass
1190 elif stype == "command":
1191 for i in psutil.process_iter(['pid', 'exe']):
1192 try:
1193 if i.status() == "zombie":
1194 continue
1195 if v_path in i.exe() and i.cwd().startswith(path.rstrip("/")):
1196 pids.append(i.pid)
1197 except:
1198 pass
1199 else:
1200 return None
1201 except:
1202 return None
1203
1204 running_pid = []
1205 other_service_pids = self.other_service_pids(project_data)
1206 for pid in pids:
1207 if pid in psutil.pids() and pid not in other_service_pids:
1208 running_pid.append(pid)
1209
1210 if len(running_pid) == 1:
1211 pid_file = "{}/{}.pid".format(self._pid_path, project_data["name"])
1212 public.writeFile(pid_file, str(running_pid[0]))
1213 return running_pid[0]
1214
1215 main_pid = []
1216 for pid in running_pid:
1217 try:
1218 p = psutil.Process(pid)
1219 if p.ppid() not in running_pid:

Callers 1

get_project_run_stateMethod · 0.95

Calls 6

other_service_pidsMethod · 0.95
writeFileMethod · 0.80
statusMethod · 0.45
joinMethod · 0.45
appendMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected