【问题标题】:How to raise exception in autobahn python ApplicationSession.__init__?如何在高速公路 python ApplicationSession.__init__ 中引发异常?
【发布时间】:2016-09-16 14:00:54
【问题描述】:

我正在尝试将 autobahn-0.16.0 与 ApplicationRunner 一起使用,如 github 上的 this example 所示。

如果我在调用 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'

【问题讨论】:

    标签: python-asyncio autobahn


    【解决方案1】:

    我相信这是 Autobahn 本身的一个微妙错误。 该库应尽早初始化所有跑步者的属性。 请在bug tracker提出问题

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    • 1970-01-01
    相关资源
    最近更新 更多