Kill all processes occupying the ports listed in PORTS_TO_CLEAN.
(ports_to_clean: list[int])
| 163 | |
| 164 | |
| 165 | def 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 | |
| 182 | def is_port_open(host: str, port: int, timeout=1.0): |
no test coverage detected