INNER CODE UNIT · Python
check_port_availability
underneathall/pinferencia · pinferencia/main.py:90
def check_port_availability(
backend_host: str,
backend_port: int,
frontend_host: str,
frontend_port: int,
mode: str = "all",
):
if backend_port == frontend_port:
raise Exception("Choose different ports for backend and frontend.")
error = ""
# check backend port
if mode != "frontend":
backend_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
backend_sock.bind((backend_host, backend_port))
except Exception: