code: def bind_sockets(
      address: str | None, port: int
  ) -> tuple[list[socket], int]:
      """Bind a socket to a port on an address.
  
      Args:
          address (str) :
              An address to bind a port on, e.g. ``"localhost"``
  
          port (int) :
              A port number to bind.
  
              Pass 0 to have the OS automatically choose a free port.
  
      This function returns a 2-tuple with the new socket as the first element,
      and the port that was bound as the second. (Useful when passing 0 as a port
      number to bind any free port.)
  
      Returns:
          (socket, port)
  
      """
      ss = netutil.bind_sockets(port=port or 0, address=address)
      assert len(ss)
      ports = {s.getsockname()[1] for s in ss}
      assert len(ports) == 1, "Multiple ports assigned??"
      actual_port = ports.pop()
      if port:
          assert actual_port == port
      return ss, actual_port
  
file_path: bokeh/src/bokeh/server/util.py
imports: from __future__ import annotations
  import logging
  from typing import TYPE_CHECKING, Sequence
  from tornado import netutil
label_desc: Use image node_id 1 for calling a global function with example usage: bind_sockets(address, port) and returns: ss,  actual_port