Kill all processes occupying the ports
(ports=None)
| 94 | |
| 95 | |
| 96 | def clean_ports(ports=None): |
| 97 | """ |
| 98 | Kill all processes occupying the ports |
| 99 | """ |
| 100 | if ports is None: |
| 101 | ports = PORTS_TO_CLEAN |
| 102 | |
| 103 | print(f"Cleaning ports: {ports}") |
| 104 | for port in ports: |
| 105 | kill_process_on_port(port) |
| 106 | |
| 107 | # Double check and retry if ports are still in use |
| 108 | time.sleep(2) |
| 109 | for port in ports: |
| 110 | if is_port_open("127.0.0.1", port, timeout=0.1): |
| 111 | print(f"Port {port} still in use, retrying cleanup...") |
| 112 | kill_process_on_port(port) |
| 113 | time.sleep(1) |
| 114 | |
| 115 | |
| 116 | def clean(ports=None): |