gpt4 book ai didi

python - gevent + redis-py : SystemError: NULL result without error in PyObject_Call

转载 作者:IT王子 更新时间:2023-10-29 06:00:52 24 4
gpt4 key购买 nike

我正在使用带有 redish 的 redis-py 和 gevent,我有自己的类 EventBot,它继承自 Greenlet。

在此类的 __init__ 方法中,我正在使用初始化与 redis 的连接

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

有时当我尝试运行脚本时,它会抛出 SystemError: NULL result without error in PyObject_Call 但有时它会正常启动。我还尝试将 redis 初始化移动到 _run() 方法,但没有帮助。

这是我使用的简化类:

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)

这是完整的回溯:

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

如有任何帮助,我们将不胜感激。


编辑:

问题似乎在使用 geventgreenlet 系统包(python2-geventpython2-greenlet 在 Arch Linux 中),但根据他们的 PKGBUILD,那里没有进行额外的修补。 ( gevent , greenlet ) 有人可以解释一下使用 pip 安装有什么问题吗?

最佳答案

使用 GCC 4.8 时,greenlet==0.4.0 似乎有问题。

如果您没有较旧的 gcc 或其他编译器可用,您可以使用 CFLAGS="-O0"pip install greenlet==0.4.0 或编辑 greenlet 的 setup.py 并调整 os.environ["CFLAGS"]

其他解决方案可能是下载并使用二进制 greenlet.so

关于python - gevent + redis-py : SystemError: NULL result without error in PyObject_Call,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15924353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com