code: def ax_client_candidate_generator(
      queue: "Queue[Tuple[TParameterization, int]]",
      stop_event: Event,
      num_trials: int,
      ax_client: AxClient,
      lock: Lock,
  ) -> None:
      """Thread-safe method for generating the next trial from the AxClient and
      enqueueing it to the candidate queue. The number of candidates pre-generated is
      controlled by the maximum size of the queue. Generation stops when num_trials
      trials are attached to the AxClient's experiment.
      """
      while not stop_event.is_set():
          if not queue.full():
              with lock:
                  try:
                      parameterization_with_trial_index = (
                          ax_client.get_next_trial()
                      )
                      queue.put(parameterization_with_trial_index)
  
                      # Check if candidate generation can end
                      if (
                          len(ax_client.experiment.arms_by_name)
                          >= num_trials
                      ):
                          stop_event.set()
  
                  except (
                      MaxParallelismReachedException,
                      DataRequiredError,
                  ) as e:
                      logger.warning(
                          f"Encountered error {e}, sleeping for {IDLE_SLEEP_SEC} "
                          "seconds and trying again."
                      )
                      pass  # Try again later
  
          time.sleep(IDLE_SLEEP_SEC)
  
file_path: Ax/ax/service/interactive_loop.py
imports: import time
  from logging import Logger
  from queue import Queue
  from threading import Event, Lock, Thread
  from typing import Any, Callable, Dict, Optional, Tuple
  from ax.core.types import TEvaluationOutcome, TParameterization
  from ax.exceptions.core import DataRequiredError
  from ax.exceptions.generation_strategy import MaxParallelismReachedException
  from ax.service.ax_client import AxClient
  from ax.utils.common.logger import get_logger
label_desc: Use image node_id 3 for calling a global function with example usage: ax_client_candidate_generator(queue, stop_event, num_trials, ax_client, lock) without return types