From 7762c88db6c2806a72a01167f2f8f56169d79e27 Mon Sep 17 00:00:00 2001 From: Jalin Date: Sat, 19 Jan 2019 11:56:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8A=82=E7=82=B9=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E6=B6=88=E6=81=AF=E4=B8=A2=E5=A4=B1=E9=87=8D=E8=BF=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py12306/cluster/cluster.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/py12306/cluster/cluster.py b/py12306/cluster/cluster.py index e8d8bdb..d6aa784 100644 --- a/py12306/cluster/cluster.py +++ b/py12306/cluster/cluster.py @@ -202,7 +202,12 @@ class Cluster(): def subscribe(self): while True: - message = self.pubsub.get_message() + try: + message = self.pubsub.get_message() + except RuntimeError as err: + if 'args' in dir(err) and err.args[0].find('pubsub connection not set') >= 0: # 失去重连 + self.pubsub.subscribe(self.KEY_CHANNEL_LOG, self.KEY_CHANNEL_EVENT) + continue if message: if message.get('type') == 'message' and message.get('channel') == self.KEY_CHANNEL_LOG and message.get( 'data'):