MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / clean_ports

Function clean_ports

tests/model_loader/utils.py:165–179  ·  view source on GitHub ↗

Kill all processes occupying the ports listed in PORTS_TO_CLEAN.

(ports_to_clean: list[int])

Source from the content-addressed store, hash-verified

163
164
165def clean_ports(ports_to_clean: list[int]):
166 """
167 Kill all processes occupying the ports listed in PORTS_TO_CLEAN.
168 """
169 print(f"Cleaning ports: {ports_to_clean}")
170 for port in ports_to_clean:
171 kill_process_on_port(port)
172
173 # Double check and retry if ports are still in use
174 time.sleep(2)
175 for port in ports_to_clean:
176 if is_port_open("127.0.0.1", port, timeout=0.1):
177 print(f"Port {port} still in use, retrying cleanup...")
178 kill_process_on_port(port)
179 time.sleep(1)
180
181
182def is_port_open(host: str, port: int, timeout=1.0):

Callers 1

run_with_timeoutFunction · 0.70

Calls 4

printFunction · 0.85
kill_process_on_portFunction · 0.70
is_port_openFunction · 0.70
sleepMethod · 0.45

Tested by

no test coverage detected