Random timeout error with Pika and gevent

I am trying to use RabbitMQ from my gevent program using the Pika library (monkey fixed by gevent), gevent likes to randomly throw a timeout error.

What should I do? Is there any other library that I could use?

WARNING:root:Document not found, retrying primary.
Traceback (most recent call last):
  ...
  File "/usr/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 32, in __init__
    BaseConnection.__init__(self, parameters, None, reconnection_strategy)
  File "/usr/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 50, in __init__
    reconnection_strategy)
  File "/usr/lib/python2.7/dist-packages/pika/connection.py", line 170, in __init__
    self._connect()
  File "/usr/lib/python2.7/dist-packages/pika/connection.py", line 228, in _connect
    self.parameters.port or  spec.PORT)
  File "/usr/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 44, in _adapter_connect
    self._handle_read()
  File "/usr/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 151, in _handle_read
    data = self.socket.recv(self._suggested_buffer_size)
  File "/usr/lib/python2.7/dist-packages/gevent/socket.py", line 427, in recv
    wait_read(sock.fileno(), timeout=self.timeout, event=self._read_event)
  File "/usr/lib/python2.7/dist-packages/gevent/socket.py", line 169, in wait_read
    switch_result = get_hub().switch()
  File "/usr/lib/python2.7/dist-packages/gevent/hub.py", line 164, in switch
    return greenlet.switch(self)
timeout: timed out
+5
source share
2 answers

Pika is not ideal for use with gevent because pika implements its own asynchronous connection to RabbitMQ based on non-blocking sockets. It just is not suitable for implementing a gevent of the same.

You might want to use py-amqplib or kombu

+5
source

Pika Django/Gunicorn. connection_attempts , RabbitMQ . , -, , Pika .

libevent - , script, , .

gevent >= 1.0 ( ):

wget http://gevent.googlecode.com/files/gevent-1.0b4.tar.gz
pip install gevent-1.0b4.tar.gz
0

All Articles