Get message(s) from the outgoing message stack.

    Blocks until an item at stack position pos becomes available.
    This method is thread safe.

    Args:
       pos: An int specifying the top position of the message stack to access.
         For example, if the stack counter is at 3 and pos == 2, then the 2nd
         item on the stack will be returned, together with an int that indicates
         the current stack heigh (3 in this case).

    Returns:
      1. The item at stack position pos.
      2. The height of the stack when the retun values are generated.

    Raises:
      ValueError: If input `pos` is zero or negative.

def get(self, pos):
    """Get message(s) from the outgoing message stack.

    Blocks until an item at stack position pos becomes available.
    This method is thread safe.

    Args:
       pos: An int specifying the top position of the message stack to access.
         For example, if the stack counter is at 3 and pos == 2, then the 2nd
         item on the stack will be returned, together with an int that indicates
         the current stack heigh (3 in this case).

    Returns:
      1. The item at stack position pos.
      2. The height of the stack when the retun values are generated.

    Raises:
      ValueError: If input `pos` is zero or negative.
    """
    if pos <= 0:
      raise ValueError('Invalid pos %d: pos must be > 0' % pos)
    with self._outgoing_lock:
      if self._outgoing_counter >= pos:
        # If the stack already has the requested position, return the value
        # immediately.
        return self._outgoing[pos - 1], self._outgoing_counter
      else:
        # If the stack has not reached the requested position yet, create a
        # queue and block on get().
        if pos not in self._outgoing_pending_queues:
          self._outgoing_pending_queues[pos] = []
        q = queue.Queue(maxsize=1)
        self._outgoing_pending_queues[pos].append(q)

    value = q.get()
    with self._outgoing_lock:
      return value, self._outgoing_counter