def METHOD_NAME(query,
         address=DEFAULT_ADDRESS,
         port=DEFAULT_PORT,
         ttl=DEFAULT_TTL,
         local_only=False,
         timeout_s=2):
  """Sends a query to the given multicast socket and returns responses.
  Args:
    query: The string query to send.
    address: Multicast IP address component of the socket to send to.
    port: Multicast UDP port component of the socket to send to.
    ttl: TTL for multicast messages. 1 to keep traffic in-network.
    local_only: if True, no packets will leave this host.
    timeout_s: Seconds to wait for responses.
  Yields:
    A set of all responses that arrived before the timeout expired.
    Responses are tuples of (sender_address, message).
  """
  # Set up the socket as a UDP Multicast socket with the given timeout.
  sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl)
  if local_only:
    # Set outgoing interface to localhost to ensure no packets leave this host.
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_IF,
                    struct.pack('!L', LOCALHOST_ADDRESS))
  sock.settimeout(timeout_s)
  sock.sendto(query.encode('utf-8'), (address, port))
  # Set up our thread-safe Queue for handling responses.
  recv_queue = queue.Queue()
  def _handle_responses():
    """Collects responses in the receive queue as soon as they are received."""
    while True:
      try:
        data, address = sock.recvfrom(MAX_MESSAGE_BYTES)
      except socket.timeout:
        break  # Give up, all stations have likely responded.
      else:
        data = data.decode('utf-8')
        _LOG.debug('Multicast response to query "%s": %s:%s', query, address[0],
                   data)
        recv_queue.put((address[0], data))
  response_thread = threading.Thread(target=_handle_responses)
  response_thread.start()
  while not recv_queue.empty() or response_thread.is_alive():
    try:
      recv_tuple = recv_queue.get(block=True, timeout=timeout_s)
    except queue.Empty:
      continue  # Retry until the thread is no longer alive.
    yield recv_tuple