В настоящее время я использую приведенный ниже код, и он, кажется, работает. Не могли бы вы сообщить мне, если это создаст проблему
try:
pikaClient = socketio.start_background_task(pika_client)
socketio.run(app, host='192.168.1.214')
except KeyboardInterrupt:
pikaClient.join()
def pika_client():
global connection, channel
params = pika.ConnectionParameters(heartbeat=600,
blocked_connection_timeout=300)
connection = pika.BlockingConnection(params)
channel = connection.channel()
print('Connection created')
while True:
time.sleep(650)
try:
connection.process_data_events()
except pika.exceptions.StreamLostError:
print("Will try to re-connect next.")
params = pika.ConnectionParameters(heartbeat=600,
blocked_connection_timeout=300)
connection = pika.BlockingConnection(params)
channel = connection.channel()
print('Connection re-created')
#continue
except KeyboardInterrupt:
# Gracefully close the connection
channel.close()
connection.close()