Viktor Stískala Viktor Stískala - 1 year ago 153
Python Question

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.

In the

method of this class I am initialising connection to redis using

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. I also tried moving the redis initialization to the
method, but it didn't helped.

This is the simplified class I am using:

from gevent import monkey, Greenlet

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

class EventBot(ClientXMPP, Greenlet):
'host': 'localhost',
'port': 6379,
'db': ""

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

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

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

## Class simplified for better readability ##

def _run(self):

Here is the complete traceback:

Traceback (most recent call last):
File "", line 15, in <module>
bot = EventBot('', 'XXXpasswordXXX')
File "/tmp/sandbox/gmarie/gmarie/marie/", line 41, in __init__
self._questions = self._redis[QUESTIONS_KEY]
File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redish/", line 196, in __getitem__
value = self.api.get(name)
File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redis/", line 551, in get
return self.execute_command('GET', name)
File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redis/", line 360, in execute_command
File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redis/", line 301, in send_command
File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redis/", line 283, in send_packed_command
File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redis/", line 228, in connect
sock = self._connect()
File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/redis/", line 240, in _connect
sock.connect((, self.port))
File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/gevent/", line 376, in connect
wait_readwrite(sock.fileno(), event=self._rw_event)
File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/gevent/", line 215, in wait_readwrite
switch_result = get_hub().switch()
File "/tmp/sandbox/gmarie/venv/lib/python2.7/site-packages/gevent/", 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/'> ignored

Any help would be greatly appreciated.


Problem seems to be fixed when using
system packages (
in Arch Linux), but according to their PKGBUILD no additional patching is done there. (gevent, greenlet) Can someone explain what is wrong with installing using pip?

Answer Source

There seems to be a problem with greenlet==0.4.0 when using GCC 4.8.

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 and tweaking os.environ["CFLAGS"].

Other solution may be to download and use the binary

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download