我正在尝试使用带有ApplicationRunner的autobahn-0.16.0,如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()
当我对raise
中的__init__
发表评论时,我收到此错误:
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'