title: gevent + redis-py: SystemError: NULL result without error in PyObject_Call
body: <p>I am using redis-py with redish together with gevent and I have my own class EventBot which inherits from Greenlet.</p>
  
  <p>In the <code>__init__</code> method of this class I am initialising connection to redis using</p>
  
  <pre class="lang-py prettyprint-override"><code>self._redis = Client(serializer=serialization.JSON(), **self.REDIS_CONFIG)
  </code></pre>
  
  <p>Sometimes when I try to run the script, it throws <code>SystemError: NULL result without error in PyObject_Call</code> but sometimes it starts normally. I also tried moving the redis initialization to the <code>_run()</code> method, but it didn't helped.</p>
  
  <p>This is the simplified class I am using:</p>
  
  <pre class="lang-py prettyprint-override"><code>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)
  </code></pre>
  
  <p>Here is the complete traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "start.py", line 15, in &lt;module&gt;
      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 &lt;module 'threading' from '/usr/lib64/python2.7/threading.py'&gt; ignored
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Problem seems to be fixed when using <code>gevent</code> and <code>greenlet</code> system packages (<code>python2-gevent</code> and <code>python2-greenlet</code> in Arch Linux), but according to their PKGBUILD no additional patching is done there. (<a href="https://projects.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/python2-gevent" rel="nofollow">gevent</a>, <a href="https://projects.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/python2-greenlet" rel="nofollow">greenlet</a>) Can someone explain what is wrong with installing using pip?</p>