code: def find_available_port():
      
      s = socket.socket()
      s.bind(('localhost', 0))
      _address, port = s.getsockname()
      s.close()
      return port
docs: Find an available port.
  
      Simple trick: open a socket to localhost, see what port was allocated.
  
      Could fail in highly concurrent setups, though.