docs: def _monitor(self):
          """Monitor the queue for items, and ask the handler to deal with them.
  
          This method runs on a separate, internal thread.
          The thread will terminate if it sees a sentinel object in the queue.
          """
          err_msg = ("invalid internal state:"
                     " _stop_nowait can not be set if _stop is not set")
          assert self._stop.isSet() or not self._stop_nowait.isSet(), err_msg
  
          q = self.queue
          has_task_done = hasattr(q, 'task_done')
          while not self._stop.isSet():
              try:
                  record = self.dequeue(True)
                  if record is self._sentinel_item:
                      break
                  self.handle(record)
                  if has_task_done:
                      q.task_done()
              except queue.Empty:
                  pass
  
          # There might still be records in the queue,
          # handle then unless _stop_nowait is set.
          while not self._stop_nowait.isSet():
              try:
                  record = self.dequeue(False)
                  if record is self._sentinel_item:
                      break
                  self.handle(record)
                  if has_task_done:
                      q.task_done()
              except queue.Empty:
                  break