2013-10-08 44 views
0

我使用一個類的方法中的蟒蛇,並從我做pika的on_open_error_callback方法簽名是什麼樣子的?

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) 
[[email protected] ~/house/test]$ 

我一直無法找到任何文件,顯示此回調的實際方法簽名。我懷疑它尋找方法的非類定義(即沒有自己作爲參數)。那是對的嗎?如果是這樣的話?那麼如何才能訪問類變量,以便我可以嘗試重新連接連接錯誤?

我想我首先要找的是我的方法簽名應該是什麼樣子?

在此先感謝

回答

0

所以看起來我能回答我自己做我的代碼下面的轉換問題。

通過轉換我的代碼執行以下操作:

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) 

它給了我現在指向我的源代碼在鼠兔新線新的崩潰地址:

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) 

所以即使我一樣糟糕,我顯然現在有我正在尋找的方法簽名。

0

只因爲我自己走了這條路,似乎簽名已經在0.10.0更改了。現在是:

def _on_connection_error(self, connection_unused, error_message=None): 
相關問題