Ref : https://github.com/python/cpython/pull/25174

https://github.com/localstack/localstack/blob/5a5edcd9d9ccbd6a56f23d71e3a1131b8c814996/localstack/utils/common.py#L324
if not is_port_open(port, http_path=http_path, expect_success=expect_success):
            raise Exception('Port %s (path: %s) was not open' % (port, http_path))
    return retry(check, sleep=sleep_time, retries=retries)
def port_can_be_bound(port):
    """ Return whether a local port can be bound to. Note that this is a stricter check
        than is_port_open(...) above, as is_port_open() may return False if the port is
        not accessible (i.e., does not respond), yet cannot be bound to. """
    try:
        tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        tcp.bind(('', port))
        return True
    except Exception:
        return False
def get_free_tcp_port(blacklist=None):
    blacklist = blacklist or []
    for i in range(10):
        tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        tcp.bind(('', 0))
        addr, port = tcp.getsockname()
        tcp.close()
        if port not in blacklist:
            return port
    raise Exception('Unable to determine free TCP port with blacklist %s' % blacklist)
def sleep_forever():
    while True:
        time.sleep(1)
def get_service_protocol():
    return 'https' if config.USE_SSL else 'http'
def edge_ports_info():