code: def find_open_port(ip, port, n=50):
      """Find an open port near the specified port"""
      ports = itertools.chain(
          (port + i for i in range(n)),
          (port + random.randint(-2 * n, 2 * n)),
      )
  
      for port in ports:
          s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          result = s.connect_ex((ip, port))
          s.close()
          if result != 0:
              return port
      raise ValueError("no open ports found")
  
file_path: altair/altair/utils/server.py
imports: import sys
  import threading
  import webbrowser
  import socket
  from http import server
  from io import BytesIO
  import itertools
  import random
label_desc: Use image node_id 2 for calling a global function with example usage: find_open_port(ip, port, n) and returns: port