线程stompReceiveThread1中出现异常

2024-05-01 21:34:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了这个错误:

Exception in thread StompReceiverThread-1 (most likely raised during interpreter shutdown):

那根本不是回溯。。就这样。 通常一切正常,但很少发生,然后行动没有结束。你知道吗

有什么建议吗? 我的代码:

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))

Tags: selfmessagedataresponserequestdefexceptionerror
1条回答
网友
1楼 · 发布于 2024-05-01 21:34:01

看起来您的主程序正在退出,解释器正在清理东西,但是stomp receiver线程并没有首先关闭。接收器线程执行某些操作,但基本模块不再可用,因此它会发出异常消息,但无法打印回溯,因为由于程序退出,该功能不再可用。你知道吗

看看为什么主程序会退出。你知道吗

相关问题 更多 >