Get multiple items from a Queue.

    Gets at least one (blocking) and at most ``max_items`` items
    (non-blocking) from a given Queue. Does not mark the items as done.

    Args:
        queue_ (~queue.Queue`): The Queue to get items from.
        max_items (int): The maximum number of items to get. If ``None``, then
            all available items in the queue are returned.
        max_latency (float):  The maximum number of seconds to wait for more
            than one item from a queue. This number includes the time required
            to retrieve the first item.

    Returns:
        Sequence[Any]: A sequence of items retrieved from the queue.

def _get_many(queue_, max_items=None, max_latency=0):
    """Get multiple items from a Queue.

    Gets at least one (blocking) and at most ``max_items`` items
    (non-blocking) from a given Queue. Does not mark the items as done.

    Args:
        queue_ (~queue.Queue`): The Queue to get items from.
        max_items (int): The maximum number of items to get. If ``None``, then
            all available items in the queue are returned.
        max_latency (float):  The maximum number of seconds to wait for more
            than one item from a queue. This number includes the time required
            to retrieve the first item.

    Returns:
        Sequence[Any]: A sequence of items retrieved from the queue.
    """
    start = time.time()
    # Always return at least one item.
    items = [queue_.get()]
    while max_items is None or len(items) < max_items:
        try:
            elapsed = time.time() - start
            timeout = max(0, max_latency - elapsed)
            items.append(queue_.get(timeout=timeout))
        except queue.Empty:
            break
    return items