pika的on_open_error_callback方法签名是什么样的?

时间:2013-10-08 18:03:26

标签: python pika

我正在使用python并且在我所做的类的方法中

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)

在我的源代码中,我将方法声明为(在一个类中):

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

但是在运行时我收到以下错误:

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]$  

我无法找到任何显示此回调的实际方法签名的文档。我怀疑它正在寻找方法的非类定义(即没有self作为参数)。那是对的吗?如果是这样的话?那么如何才能访问类变量,以便重新连接连接错误?

我想我首先想要的是我的方法签名应该是什么样的?

提前致谢

2 个答案:

答案 0 :(得分:1)

所以看起来我能够通过对代码进行以下转换来回答我自己的问题。

转换我的代码以执行以下操作:

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)

它给了我一个新的崩溃地址,现在我指出了一个新的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

查看connection.py依次产生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)

所以,即使我一样糟糕,我现在显然已经找到了我想要的方法签名。

答案 1 :(得分:0)

只是因为我自己走了这条路,似乎签名在0.10.0中已经改变了。现在是:

DECLARE @p0 varbinary(max);
SET @p0 = 0x.........; // LOT OF BYTES 

SELECT Orders.Id, Reflinks.Rate1
FROM Orders
INNER JOIN Users ON Orders.UserId = Users.Id
INNER JOIN Reflinks ON Users.ReflinkId = Reflinks.Id

SELECT Orders.Id, Reflinks.Rate1
FROM SplitIds(@p0) AS t0
INNER JOIN Orders ON t0.Id = Orders.Id
INNER JOIN Users ON Orders.UserId = Users.Id
INNER JOIN Reflinks ON Users.ReflinkId = Reflinks.Id