def _getMessage(session, txid):
    """Getting message associated with txid"""

    while True:
        if txid in session.messages:
            msg = session.messages[txid]
            del session.messages[txid]
            return msg
        else:
            try:
                # apparently any timeout at all allows the thread to be
                # stopped but none make it unstoppable with ctrl+c
                nextMessage = session.queue.get(timeout=100)
            except queue.Empty:
                continue
            if 'txid' in nextMessage:
                session.messages[nextMessage['txid']] = nextMessage
            else:
                logger.info("message with no txid: %s" % nextMessage)
Getting message associated with txid