If an exception occurs on the server side, or the connection port or server restarts, how can the client catch the exception and re-establish the connection?
my code
`
from Model.RecordModel import RecordModel
from Model.ImageVars import ImageVars
import json
import socket
import threading
import time
import traceback
import logging
import rabbitpy
import DAO.Record
from BLL.MemcacheHelper import cache_get, cache_set
from BLL.RedisHelper import redis_client, acquire_lock, q_lock, release_lock
from BLL.Task2.Step1_YuChuLiThread import Step1_YuChuLi_AppendTask
from BLL.Task2.Upload2OSS_Thread import 上传到OSSV3
from DAO.SuanLiFenPei import GetSuanLiFenPeiConfig
from Config import Seting
from timeline.TaskTimeLine_MySql import InitTimeLine, SaveRecord, TEnd, TStart
from BLL.RabbitMQConsumer import Consumer
from BLL.RabbitMQHelper import MQConnection, SendMQ, getMQConnection,clearMQConnection
If an exception occurs on the server side, or the connection port or server restarts, how can the client catch the exception and re-establish the connection? my code `
from Model.RecordModel import RecordModel from Model.ImageVars import ImageVars import json
import socket
import threading import time import traceback import logging import rabbitpy
import DAO.Record
from BLL.MemcacheHelper import cache_get, cache_set
from BLL.RedisHelper import redis_client, acquire_lock, q_lock, release_lock
from BLL.Task2.Step1_YuChuLiThread import Step1_YuChuLi_AppendTask
from BLL.Task2.Upload2OSS_Thread import 上传到OSSV3
from DAO.SuanLiFenPei import GetSuanLiFenPeiConfig
from Config import Seting
from timeline.TaskTimeLine_MySql import InitTimeLine, SaveRecord, TEnd, TStart
from BLL.RabbitMQConsumer import Consumer
from BLL.RabbitMQHelper import MQConnection, SendMQ, getMQConnection,clearMQConnection
def InitGetJobFromRebbitMQ(processMsgFN): ''' 通过RabbitMQ取任务 '''
queuename = 'Q.AIDetect.AIDetect.on.WebAPI.PhotoIsTaken'
def LoopMessage(mqqueue:rabbitpy.Queue, processMsgFN):
`
BLL/RabbitMQHelper.py ` import time import traceback from Config import Seting import logging
import rabbitpy
URL = 'amqp://'+str(Seting.RabbitMQ_UserName)+':'+ str(Seting.RabbitMQ_Password)+'@'+str(Seting.RabbitMQ_IP)+':'+str(Seting.RabbitMQ_Port)+'/%2f?heartbeat=60' MQConnection = None MQChannel = None
def clearMQConnection(): global MQConnection,MQChannel
def getMQConnection(): global MQConnection if(MQConnection is None or MQConnection.closed): MQConnection = rabbitpy.Connection(URL)
`
I found two bugs,
One is that when the server is restarted,
for message in mqqueue:
The other is that when the server has just started successfully,
with MQConnection. channel() as MQchannel: