import queue


def get_all_from_queue(q):
    """Returns all items that are currently in a (queue|multiprocessing).Queue, as a list.
    (Theoretically, if the queue grows faster than it can be read out, this function may never
    return.)

    Args:
        q: The queue.Queue or mp.Queue from which to retrieve the items.
    """

    items = []
    try:
        while True:
            items.append(q.get_nowait())
    except queue.Empty:
        return items