3

在什么情况下会redis-py引发以下AttributeError异常?
不是redis-py设计为仅引发redis.exceptions.RedisError基于异常的吗?
什么是合理的处理逻辑?

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 33, in inner
    ret = protected_func(*args, **kwargs)
  File C:\Users\Administrator\Documents\my_proj\my_module.py", line 104, in _listen
    for message in _pubsub.listen():
  File "C:\Users\Administrator\virtual_environments\my_env\lib\site-packages\redis\client.py", line 1555, in listen
    r = self.parse_response()
  File "C:\Users\Administrator\virtual_environments\my_env\lib\site-packages\redis\client.py", line 1499, in parse_response
    response = self.connection.read_response()
  File "C:\Users\Administrator\virtual_environments\my_env\lib\site-packages\redis\connection.py", line 306, in read_response
    response = self._parser.read_response()
  File "C:\Users\Administrator\virtual_environments\my_env\lib\site-packages\redis\connection.py", line 104, in read_response
    response = self.read()
  File "C:\Users\Administrator\virtual_environments\my_env\lib\site-packages\redis\connection.py", line 89, in read
    return self._fp.readline()[:-2]
AttributeError: 'NoneType' object has no attribute 'readline'
4

1 回答 1

0

似乎是一个老问题,但我最近遇到了同样的问题。我的设置是使用 celery 和 redis 作为代理。ThreadPoolExecutor 使用共享的 celery 对象将任务批处理给工作人员。批处理器函数等待提交的任务使用celery.result.ResultSet.

经过快速调查,我发现某处的 celery 使用 pub/sub 机制来等待任务完成。就是这样,根据官方自述https://github.com/andymccurdy/redis-py#thread-safety,pub/sub在线程安全方面表现不佳

老实说,我并没有试图证明我的理论,而是通过切换到 ProcessPoolExecutor 来解决我的问题。

于 2018-06-14T15:16:24.380 回答