使用 redis-py 的 PubSub 类,我有时会遇到以下异常:
Exception in thread listener_2013-10-24 12:50:31.687000:
Traceback (most recent call last):
File "c:\Python27\Lib\threading.py", line 551, in __bootstrap_inner
self.run()
File "c:\Python27\Lib\threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\Users\Administrator\Documents\my_proj\my_module.py", line 69, in _listen
for message in _pubsub.listen():
File "C:\Users\Administrator\virtual_environments\spyker\lib\site-packages\redis\client.py", line 1555, in listen
r = self.parse_response()
File "C:\Users\Administrator\virtual_environments\spyker\lib\site-packages\redis\client.py", line 1499, in parse_response
response = self.connection.read_response()
File "C:\Users\Administrator\virtual_environments\spyker\lib\site-packages\redis\connection.py", line 306, in read_response
response = self._parser.read_response()
File "C:\Users\Administrator\virtual_environments\spyker\lib\site-packages\redis\connection.py", line 106, in read_response
raise ConnectionError("Socket closed on remote end")
ConnectionError: Socket closed on remote end
什么会导致这样的事件?
如果我捕捉到这个异常,什么是合理的处理逻辑?重试listen()
会徒劳吗?
问而不是简单地尝试的原因是我不知道如何重现这个问题。这种情况很少见,但很有害,因此我必须在此错误再次发生之前创建一些逻辑。