线程StompReceiverThread-1中的异常

时间:2018-10-29 16:26:11

标签: python multithreading python-multithreading stomp

我遇到此错误:

  

线程StompReceiverThread-1中的异常(最有可能在   解释器关闭):

那根本不是追溯。 通常,一切正常,但很少发生,然后动作无法结束。

有什么提示吗? 我的代码:

class Listener(stomp.ConnectionListener):
    def __init__(self, conn, request):
        self.conn = conn
        self.request = request
    def on_error(self, headers, message):
        global WAITING_RESPONSE
        print('received an error: ' + message)
        WAITING_RESPONSE = False

    def on_message(self, headers, message):
        global WAITING_RESPONSE
        try:
            msg = json.loads(message)
            if str(msg.get('transaction_id','')) == str(CURRENT_ID):
                printDebugLine('Queue response:'+str(message))
                manageQueueResponse(message,self.request)
                WAITING_RESPONSE = False
            self.conn.ack(headers['message-id'], '11')

        except stomp.exception.ConnectFailedException:
            print('Stomp error on message')
            sys.exit(3)
        except Exception as e:
            print('ERROR: %s' % str(e))
            sys.exit(3)

class Queue(object):
def __init__(self):
    self.host = xx
    self.port = xx
    self.login = xx
    self.passwd = xx
    self.request = {}
    self.start()

def start(self):
    try:
        self.conn = stomp.Connection(host_and_ports=[(self.host, self.port)])
        self.conn.start()
        self.conn.connect(self.login, self.passwd, wait=True)
        self.conn.set_listener('xx', Listener(self.conn, self.request))
        self.conn.subscribe(destination='xx', id='xx', ack='xx')
    except stomp.exception.ConnectFailedException:
        print('ERROR: unable to connect')
        sys.exit(3)
    except Exception as e:
        print('ERROR: %s' % str(e))
        sys.exit(3)

def send(self, data):
    global CURRENT_ID
    while WAITING_RESPONSE:
        time.time(0.1)

    try:
        CURRENT_ID = str(uuid.uuid4())
        data.update({'transaction_id': CURRENT_ID})
        b = json.dumps(data)
        self.request.update(data)
        printDebugLine('Queue request:'+str(data))
        self.conn.send(body=b, destination='xx')
        timeout(data,self.request,29)

    except stomp.exception.ConnectFailedException:
        print('ERROR: unable to connect')
    except Exception as e:
        print('ERROR: %s' % str(e))

1 个答案:

答案 0 :(得分:0)

看起来您的主程序正在退出,解释器正在清理内容,但是stomp接收器线程并未首先关闭。接收器线程可以做一些事情,但是基本模块不再可用,因此它会发出异常消息,但是由于由于程序退出而无法再使用该功能,因此无法打印回溯。

看看为什么要退出主程序。