2016-09-16 19 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