def WorkOnItems(self):
    """Perform the work of a WorkerThread."""
    while not self.exit_flag:
      item = None
      self.__thread_gate.StartWork()

      try:

        status, instruction = WorkItem.FAILURE, ThreadGate.DECREASE


        try:
          if self.exit_flag:

            instruction = ThreadGate.HOLD
            break


          try:
            item = self.__work_queue.get(block=True, timeout=1.0)
          except Queue.Empty:

            instruction = ThreadGate.HOLD
            continue
          if item == _THREAD_SHOULD_EXIT or self.exit_flag:


            status, instruction = WorkItem.SUCCESS, ThreadGate.HOLD
            break

          logger.debug('[%s] Got work item %s', self.getName(), item)

          status, instruction = item.PerformWork(self.__thread_pool)
        except RetryException:
          status, instruction = WorkItem.RETRY, ThreadGate.HOLD
        except:
          self.SetError()
          raise

      finally:

        try:

          if item:
            if status == WorkItem.SUCCESS:
              self.__work_queue.task_done()
            elif status == WorkItem.RETRY:


              try:
                self.__work_queue.reput(item, block=False)
              except Queue.Full:
                logger.error('[%s] Failed to reput work item.', self.getName())
                raise Error('Failed to reput work item')
            else:
              if not self.__error:
                if item.error:
                  self.__error = item.error
                  self.__traceback = item.traceback
                else:

                  self.__error = WorkItemError(
                      'Fatal error while processing %s' % item)

                raise self.__error

        finally:
          self.__thread_gate.FinishWork(instruction=instruction)
dataset/ETHPy150Open GoogleCloudPlatform/python-compat-runtime/appengine-compat/exported_appengine_sdk/google/appengine/tools/adaptive_thread_pool.py/WorkerThread.WorkOnItems/original