Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random timeout error with Pika and gevent

I've been trying to make use of RabbitMQ from within my gevent program by using the Pika library (monkey patched by gevent), gevent likes randomly throwing a timeout error.

What should I do? Is there another library 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
like image 570
Noah McIlraith Avatar asked Jun 28 '12 08:06

Noah McIlraith


1 Answers

Pika is not ideally suited to use with gevent because pika implements its own asynchronous connection to RabbitMQ based on non-blocking sockets. This just does not fit well with gevent's implementation of the same.

You may want to consider using py-amqplib or kombu

like image 95
akent Avatar answered Oct 03 '22 18:10

akent