code: def _await_flow(self, client, flow_id):
      
      # Wait for the flow to finish
      print('{0:s}: Waiting to finish'.format(flow_id))
      while True:
        try:
          status = client.Flow(flow_id).Get().data
        except grr_errors.UnknownError:
          msg = 'Unable to stat flow {0:s} for host {1:s}'.format(
              flow_id, client.data.os_info.fqdn.lower())
          self.state.add_error(msg)
          raise DFTimewolfError(
              'Unable to stat flow {0:s} for host {1:s}'.format(
                  flow_id, client.data.os_info.fqdn.lower()))
  
        if status.state == flows_pb2.FlowContext.ERROR:
          # TODO(jbn): If one artifact fails, what happens? Test.
          message = status.context.backtrace
          if 'ArtifactNotRegisteredError' in status.context.backtrace:
            message = status.context.backtrace.split('\n')[-2]
          raise DFTimewolfError(
              '{0:s}: FAILED! Message from GRR:\n{1:s}'.format(
                  flow_id, message))
  
        if status.state == flows_pb2.FlowContext.TERMINATED:
          print('{0:s}: Complete'.format(flow_id))
          break
        time.sleep(self._CHECK_FLOW_INTERVAL_SEC)
docs: Awaits flow completion.
  
      Args:
        client: GRR Client object in which to await the flow.
        flow_id: string containing ID of flow to await.
  
      Raises:
        DFTimewolfError: if flow error encountered.