简体   繁体   English

gevent + redis-py:SystemError:在PyObject_Call中没有错误的NULL结果

[英]gevent + redis-py: SystemError: NULL result without error in PyObject_Call

I am using redis-py with redish together with gevent and I have my own class EventBot which inherits from Greenlet. 我正在使用带有redvent和redvent的redis-py,我有自己的类EventBot,它继承自Greenlet。

In the __init__ method of this class I am initialising connection to redis using 在这个类的__init__方法中,我正在初始化与redis的连接

self._redis = Client(serializer=serialization.JSON(), **self.REDIS_CONFIG)

Sometimes when I try to run the script, it throws SystemError: NULL result without error in PyObject_Call but sometimes it starts normally. 有时当我尝试运行脚本时,它会SystemError: NULL result without error in PyObject_Call抛出SystemError: NULL result without error in PyObject_Call但有时它会正常启动。 I also tried moving the redis initialization to the _run() method, but it didn't helped. 我也尝试将redis初始化移动到_run()方法,但它没有帮助。

This is the simplified class I am using: 这是我正在使用的简化类:

from gevent import monkey, Greenlet
monkey.patch_all()

from sleekxmpp import ClientXMPP
from redish import serialization
from redish.client import Client


class EventBot(ClientXMPP, Greenlet):
    REDIS_CONFIG = {
        'host': 'localhost',
        'port': 6379,
        'db': ""
    }

    def __init__(self, jid, password, redis_config=None):
        ClientXMPP.__init__(self, jid, password)
        Greenlet.__init__(self)

        # Redis init
        if redis_config is not None:
            self.REDIS_CONFIG.update(redis_config)
        self._redis = Client(serializer=serialization.JSON(), **self.REDIS_CONFIG)

        QUESTIONS_KEY = __name__ + '_questions'
        try:
            self._questions = self._redis[QUESTIONS_KEY]
        except KeyError:
            self._questions = self._redis[QUESTIONS_KEY] = {}

    ## Class simplified for better readability ##

    def _run(self):
        self.connect()
        self.process(block=False)

Here is the complete traceback: 这是完整的追溯:

Traceback (most recent call last):
  File "start.py", line 15, in <module>
    bot = EventBot('marie@xxx.com', 'XXXpasswordXXX')
  File "/tmp/sandbox/gmarie/gmarie/marie/eventbot.py", line 41, in __init__
    self._questions = self._redis[QUESTIONS_KEY]
  File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redish/client.py", line 196, in __getitem__
    value = self.api.get(name)
  File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redis/client.py", line 551, in get
    return self.execute_command('GET', name)
  File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redis/client.py", line 360, in execute_command
    connection.send_command(*args)
  File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redis/connection.py", line 301, in send_command
    self.send_packed_command(self.pack_command(*args))
  File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redis/connection.py", line 283, in send_packed_command
    self.connect()
  File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redis/connection.py", line 228, in connect
    sock = self._connect()
  File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redis/connection.py", line 240, in _connect
    sock.connect((self.host, self.port))
  File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/gevent/socket.py", line 376, in connect
    wait_readwrite(sock.fileno(), event=self._rw_event)
  File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/gevent/socket.py", line 215, in wait_readwrite
    switch_result = get_hub().switch()
  File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/gevent/hub.py", line 164, in switch
    return greenlet.switch(self)
SystemError: NULL result without error in PyObject_Call
Exception KeyError: KeyError(21246672,) in <module 'threading' from '/usr/lib64/python2.7/threading.py'> ignored

Any help would be greatly appreciated. 任何帮助将不胜感激。


EDIT: 编辑:

Problem seems to be fixed when using gevent and greenlet system packages ( python2-gevent and python2-greenlet in Arch Linux), but according to their PKGBUILD no additional patching is done there. 当使用geventgreenlet系统软件包(在Arch Linux中使用python2-geventpython2-greenlet )时,问题似乎得到解决,但根据他们的PKGBUILD,没有进行额外的修补。 ( gevent , greenlet ) Can someone explain what is wrong with installing using pip? geventgreenlet )有人可以解释使用pip安装有什么问题吗?

There seems to be a problem with greenlet==0.4.0 when using GCC 4.8 . 使用GCC 4.8时, greenlet==0.4.0似乎存在问题。

If you don't have older gcc or another compiler available, you can override the problem by using CFLAGS="-O0" pip install greenlet==0.4.0 or by editing greenlet's setup.py and tweaking os.environ["CFLAGS"] . 如果你没有旧的gcc或其他可用的编译器,可以使用CFLAGS="-O0" pip install greenlet==0.4.0或编辑greenlet的setup.py并调整os.environ["CFLAGS"]来覆盖问题。 os.environ["CFLAGS"]

Other solution may be to download and use the binary greenlet.so 其他解决方案可能是下载并使用二进制greenlet.so

根据关于此主题的GitHub问题 ,您还可以使用CFLAGS="-O2 -fno-tree-dominator-opts"来获得常规编译器优化但不会出现段错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM