Domanda

I'm using python and from within a method of a class I do

self.connection = pika.SelectConnection(
            self.connectionParameters,
            on_open_callback=self.onConnected,
            on_open_error_callback=self.onConnectionError,
            on_close_callback=self.onConnectionClosed,
            stop_ioloop_on_close=False)

In my source code I declare the method as (within a class):

def onConnectionError(self):
    """
    @summary: Called if the connection to rabbit is unavailable.  Attempt to connect to one of   
        the many backup servers.
    @return: ??
    """

However at runtime I am getting the following error:

Traceback (most recent call last):
  File "SpaceListener.py", line 218, in <module>
    cacheTime=args.timeout)
  File "SpaceListener.py", line 88, in __init__
    logger=self.logger)
  File "/home/centos/house/tes/castExchangeScan.py", line 108, in __init__
    stop_ioloop_on_close=False)
  File "build/bdist.linux-i686/egg/pika/adapters/select_connection.py", line 51, in __init__
  File "build/bdist.linux-i686/egg/pika/adapters/base_connection.py", line 62, in __init__
  File "build/bdist.linux-i686/egg/pika/connection.py", line 590, in __init__
  File "build/bdist.linux-i686/egg/pika/connection.py", line 707, in connect
  File "build/bdist.linux-i686/egg/pika/callback.py", line 61, in wrapper
  File "build/bdist.linux-i686/egg/pika/callback.py", line 92, in wrapper
  File "build/bdist.linux-i686/egg/pika/callback.py", line 232, in process
TypeError: onConnectionError() takes exactly 1 argument (2 given)
[centos@localhost ~/house/test]$  

I have been unable to find any documentation that shows the actual method signature of this callback. I suspect its looking for a non class definition of the method (ie no self as a parameter). Is that correct? If that is the case? how then do I get access to the class variable(s) so I can attempt a reconnection on a connection error?

I guess what I am looking for first is what should my method signature look like?

Thanks in advance

È stato utile?

Soluzione

So it looks like I was able to answer my own question by doing the following conversion of my code.

By converting my code to do the following:

self.connection = pika.SelectConnection(self.connectionParameters,
        on_open_callback=self.onConnected, on_close_callback=self.onConnectionClosed,
        stop_ioloop_on_close=False)
self.connection.add_on_open_error_callback(self.onConnectionError)

It gave me a new crash address which now points me to a new line of source code in pika:

File "build/bdist.linux-i686/egg/pika/adapters/select_connection.py", line 51, in __init__
File "build/bdist.linux-i686/egg/pika/adapters/base_connection.py", line 62, in __init__
File "build/bdist.linux-i686/egg/pika/connection.py", line 590, in __init__
File "build/bdist.linux-i686/egg/pika/connection.py", line 707, in connect
File "build/bdist.linux-i686/egg/pika/callback.py", line 61, in wrapper
File "build/bdist.linux-i686/egg/pika/callback.py", line 92, in wrapper
File "build/bdist.linux-i686/egg/pika/callback.py", line 232, in process
File "build/bdist.linux-i686/egg/pika/connection.py", line 1192, in _on_connection_error
pika.exceptions.AMQPConnectionError: 1

Looking at connection.py In turn it yields the expected method signature of on_connection_error

def _on_connection_error(self, connection_unused):
    """Default behavior when the connecting connection can not connect.

    :raises: exceptions.AMQPConnectionError

    """
    raise exceptions.AMQPConnectionError(self.params.connection_attempts)

So even though I'm just as bad off, I apparently now have the method signature I was looking for.

Altri suggerimenti

Only because I just went down this road myself, it seems that the signature has changed in 0.10.0. It is now:

def _on_connection_error(self, connection_unused, error_message=None):
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top