code: def WaitUntilNoFlowsToProcess(self, timeout=None):
      
      t = self.flow_handler_thread
      if not t:
        return
  
      start_time = time.time()
      while True:
        with self.lock:
          # If the thread is dead, or there are no requests
          # to be processed/being processed, we stop waiting
          # and return from the function.
          if (not t.isAlive() or
              (not self._GetFlowRequestsReadyForProcessing() and
               not self.flow_handler_num_being_processed)):
            return
  
        time.sleep(0.2)
  
        if timeout and time.time() - start_time > timeout:
          raise TimeOutWhileWaitingForFlowsToBeProcessedError(
              "Flow processing didn't finish in time.")
docs: Waits until flow processing thread is done processing flows.
  
      Args:
        timeout: If specified, is a max number of seconds to spend waiting.
  
      Raises:
        TimeOutWhileWaitingForFlowsToBeProcessedError: if timeout is reached.