2016-09-16 48 views
0

我試圖使用高速公路-16.0.0,與ApplicationRunner,如this example在github上所示。如何在autobahn python ApplicationSession .__ init__中引發異常?

如果在join()被調用後發生異常,則所有事情都按預期工作。但是,如果在__init__方法中引發異常,我會得到AttributeError: 'ApplicationRunner' object has no attribute 'log'。我想知道是否有辦法做到這一點。

下面的代碼是重現問題的示例。

#!/usr/bin/python3 

import txaio 

import asyncio 
from asyncio import coroutine 
from autobahn.asyncio.wamp import ApplicationSession 
from autobahn.asyncio.wamp import ApplicationRunner 

class SessionWithException(ApplicationSession): 
    def __init__(self, config): 
     ApplicationSession.__init__(self, config) 
#  raise Exception('Some error exception') 

    def onConnect(self): 
     print("Connecting...") 
     self.join(self.config.realm) 
     raise Exception('Good exception') 

    @coroutine 
    def onJoin(self, details): 
     print("Joining...") 
     self.disconnect() 

    def onDisconnect(self): 
     print("Disconnecting...") 
     asyncio.get_event_loop().stop() 

def main(): 
    txaio.start_logging(level='error') 

    runner = ApplicationRunner("wss://api.poloniex.com:443", "realm1") 
    runner.run(SessionWithException) 

if __name__ == "__main__": 
    main() 

當我出評論中__init__raise,我得到這個錯誤:

Traceback (most recent call last): 
    File "/usr/lib/python3.4/site-packages/autobahn/wamp/websocket.py", line 60, in onOpen 
    self._session = self.factory._factory() 
    File "/usr/lib/python3.4/site-packages/autobahn/asyncio/wamp.py", line 125, in create 
    self.log.failure("App session could not be created! ") 
AttributeError: 'ApplicationRunner' object has no attribute 'log' 

回答

0

我相信這是在高速公路本身就是一個微妙的錯誤。 圖書館應儘早初始化所有跑步者的屬性。 請在bug tracker

+0

上提出問題謝謝!我想象可能是這樣,但作爲一個高速公路新手,我不確定。正如我所建議的那樣,我已經發布了[問題](https://github.com/crossbario/autobahn-python/issues/737)。 – user1096555

+0

請參閱https://github.com/crossbario/autobahn-python/issues/737#issuecomment-248520738 – oberstet