def _ExecuteBackgroundThreadTasks(worker_id, task_queue, response_queue):
  """Executes tasks received on a task queue.

  Executed in a child Thread by _BackgroundThreadTaskManager.

  Args:
    worker_id: int. Identifier for the child thread relative to other child
        threads.
    task_queue: _NonPollingSingleReaderQueue. Queue from which input is read.
        Each value in the queue can be one of three types of values. If it is a
        (task_id, _BackgroundTask) pair, the task is executed on this thread.
        If it is _THREAD_STOP_PROCESSING, the thread stops executing. If it is
        _THREAD_WAIT_FOR_KEYBOARD_INTERRUPT, the thread waits for a
        KeyboardInterrupt.
    response_queue: _SingleReaderQueue. Queue to which output is written. It
        receives worker_id when this thread's bootstrap code has completed and
        receives a (worker_id, task_id) pair for each task completed on this
        thread.
  """
  try:
    response_queue.Put(worker_id)
    while True:
      task_tuple = task_queue.Get()
      if task_tuple == _THREAD_STOP_PROCESSING:
        break
      elif task_tuple == _THREAD_WAIT_FOR_KEYBOARD_INTERRUPT:
        while True:
          time.sleep(_WAIT_MAX_RECHECK_DELAY)
      task_id, task = task_tuple
      task.Run()
      response_queue.Put((worker_id, task_id))
  except __HOLE__:
    # TODO(skschneider): Detect when the log would be unhelpful (e.g. if the
    # current thread was spinning in the _THREAD_WAIT_FOR_KEYBOARD_INTERRUPT
    # sub-loop). Only log in helpful cases, like when the task is interrupted.
    logging.debug('Child thread %s received a KeyboardInterrupt from its '
                  'parent.', worker_id, exc_info=True)
dataset/ETHPy150Open GoogleCloudPlatform/PerfKitBenchmarker/perfkitbenchmarker/background_tasks.py/_ExecuteBackgroundThreadTasks