class_docstr: FlaskHelper is a class for common Flask utilities used in dashboards.
class_docstr_tok: ["FlaskHelper","is","a","class","for","common","Flask","utilities","used","in","dashboards","."]
docstr: Check whether the specified local port is available.
  
  Borrowed from:
  https://stackoverflow.com/questions/19196105/how-to-check-if-a-network-port-is-open-on-linux
docstr_tok: ["Check","whether","the","specified","local","port","is","available",".","Borrowed","from",":","https",":","\/\/stackoverflow.com\/questions\/19196105\/how-to-check-if-a-network-port-is-open-on-linux"]
code: def _is_local_port_available(ip, port, raise_error=True):
      """Check whether the specified local port is available.
  
      Borrowed from:
      https://stackoverflow.com/questions/19196105/how-to-check-if-a-network-port-is-open-on-linux
      """
      try:
          backlog = 5
          with socket.socket(
              socket.AF_INET, socket.SOCK_STREAM
          ) as sock:
              # See stack overflow to prevent "Only one usage" random
              # errors in tests:
              # https://stackoverflow.com/questions/30420512/python-socket-error-only-one-usage-of-each-socket-address-is-normally-permitted
              sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
              sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
              sock.bind((LOCALHOST, port))
              sock.listen(backlog)
      except (socket.error, OSError):  # pragma: no cover
          if raise_error:
              error_message = """Port {0} is not available.
                  Please specify another port for use via the 'port' parameter"""
              raise RuntimeError(error_message.format(port))
          else:
              return False
      return True
  
file_path: responsible-ai-toolbox/rai_core_flask/rai_core_flask/flask_helper.py
imports: import atexit
  import logging
  import socket
  import threading
  import time
  import uuid
  import warnings
  from flask import Flask
  from flask_socketio import SocketIO
  from gevent.pywsgi import WSGIServer
  from .environment_detector import build_environment
  from .environments.credentialed_vm_environment import CREDENTIALED_VM
  from .environments.public_vm_environment import PUBLIC_VM
label_desc: Use image node_id 2 for calling the FlaskHelper obj's underlying member method code with example usage: obj._is_local_port_available(ip, port, raise_error) and returns: True, False