import socket


def check_port_free(port: int) -> bool:
    """
    Check if the port is not taken on localhost.

    :param port: Port number.
    :return: True if available else False.
    """
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.connect(("localhost", port))
        return False
    except ConnectionRefusedError:
        return True
    finally:
        try:
            s.shutdown(socket.SHUT_RDWR)
        except OSError:
            pass
        s.close()