MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / _check_server_port

Method _check_server_port

launcher/runner.py:234–268  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

232 sys.exit(1)
233
234 def _check_server_port(self):
235 server_target_port = self.args.server_port
236 logger.info(f"--- Step 2: Checking if port {server_target_port} is in use ---")
237 port_is_available = False
238 uvicorn_bind_host = "0.0.0.0"
239 if is_port_in_use(server_target_port, host=uvicorn_bind_host):
240 logger.warning(f"Port {server_target_port} is currently in use.")
241 pids_on_port = find_pids_on_port(server_target_port)
242 if pids_on_port:
243 logger.warning(f"PIDs using port {server_target_port}: {pids_on_port}")
244 if self.final_launch_mode == "debug":
245 choice = (
246 input_with_timeout(
247 " Try to kill these processes? (y/n, 15s timeout): ",
248 15,
249 )
250 .strip()
251 .lower()
252 )
253 if choice == "y":
254 all(kill_process_interactive(pid) for pid in pids_on_port)
255 time.sleep(2)
256 if not is_port_in_use(
257 server_target_port, host=uvicorn_bind_host
258 ):
259 logger.info("Port is now available.")
260 port_is_available = True
261 else:
262 logger.error("Port still in use after kill attempt.")
263 else:
264 logger.error("Headless mode: will not auto-kill processes.")
265 if not port_is_available:
266 logger.warning("Continuing anyway, Uvicorn will handle binding.")
267 else:
268 logger.debug(f"[System] Port {server_target_port} is available")
269
270 def _resolve_auth_file_path(self):
271 if self.args.active_auth_json:

Callers 1

runMethod · 0.95

Calls 8

is_port_in_useFunction · 0.90
find_pids_on_portFunction · 0.90
input_with_timeoutFunction · 0.90
kill_process_interactiveFunction · 0.90
infoMethod · 0.80
warningMethod · 0.80
errorMethod · 0.80
debugMethod · 0.80

Tested by

no test coverage detected