redis-py引发了AttributeError

时间:2013-11-05 16:05:36

标签: redis-py

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'

1 个答案:

答案 0 :(得分:0)

似乎是一个老问题,但我最近遇到了同样的问题。 我的设置是使用芹菜和redis作为经纪人。 ThreadPoolExecutor使用共享celery对象将任务批处理到worker。 batcher函数等待使用celery.result.ResultSet完成提交的任务。

经过快速调查后,我发现某处的芹菜使用pub / sub机制等待任务完成。就是这样,根据官方自述文件{/ 3}}

,pub / sub不能很好地发挥线程安全性。

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