crossbario / autobahn-python

WebSocket and WAMP in Python for Twisted and asyncio
https://crossbar.io/autobahn
MIT License
2.48k stars 766 forks source link

Enabled logging eats exception backtraces #827

Closed aberres closed 7 years ago

aberres commented 7 years ago

When the default ApplicationRunner enables logging via txaio.start_logging() backtraces raised in asyncio code are not printed anymore. Only the warning itself is visible.

Consider the following snippet:

import logging
from os import environ

from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner

class MyComponent(ApplicationSession):
    async def onJoin(self, details):
        logging.info('We want a backtrace!')

        raise RuntimeError('meh')

if __name__ == '__main__':
    runner = ApplicationRunner(
        environ.get("AUTOBAHN_DEMO_ROUTER", u"ws://127.0.0.1:8080/ws"),
        u"realm1",
    )
    runner.run(MyComponent)

Output with the unmodified ApplicationRunner looks like this:

2017-04-27T11:53:11 Task exception was never retrieved
future: <Task finished coro=<onJoin() done, defined at break_it.py:20> exception=RuntimeError('meh',)>

Is this expected? It makes debugging problems kind of impossible.

When I remove the call to txaio.start_logging() I get what I expect:

ERROR:asyncio:Task exception was never retrieved
future: <Task finished coro=<onJoin() done, defined at break_it.py:20> exception=RuntimeError('meh',)>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "break_it.py", line 23, in onJoin
    raise RuntimeError('meh')
RuntimeError: meh
meejah commented 7 years ago

moved to txaio repository