def read_last_msg_from_queue(q):
    """
    Read all messages from a queue and return the last one.

    This is useful in many cases where all messages are always the complete
    state of things. Therefore, intermittent messages can be ignored.

    Doesn't block, returns None if there is no message waiting in the queue.

    """
    msg = None
    while True:
        try:
            # The list of IPs is always a full list.
            msg = q.get_nowait()
            q.task_done()
        except Queue.Empty:
            # No more messages, all done for now
            return msg
def read_last_msg_from_queue ( q ) : msg = None while True : try : msg = q . get_nowait ( ) q . task_done ( ) except Queue . Empty : return msg
Read all messages from a queue and return the last one.

    This is useful in many cases where all messages are always the complete
    state of things. Therefore, intermittent messages can be ignored.

    Doesn't block, returns None if there is no message waiting in the queue.