Logging WAMP worker Trace Back Error

别等时光非礼了梦想. 提交于 2020-01-03 05:37:08

问题


I have been trying to debug Remote Procedure Calls for WAMP (Web Application Messaging Protocol) based python components. For example:

Front end (browser)

session.call('math.add2', [2, 'two']);

Back end (python)

@wamp.register("math.add2")
def add2(self, x, y):
    return x + y

It gives a little bit of idea about the error.

For a simple example like this, it doesn't really matter at all but for large applications with a lot of files and modules, Im not quite sure about the best way to pin point the errors so that it outputs the full error trace with file name, line number and description.

As a solution, I have slightly modified the wamp.py (added the line traceback.print_exc()) like below to output the errors on the console log:

# autobahn/asyncio/wamp.py
...
import traceback
...

class FutureMixin:
  ...
  @staticmethod
  def _as_future(fun, *args, **kwargs):
     try:
        res = fun(*args, **kwargs)
     except Exception as e:
        traceback.print_exc() # Added this line
        ...

Is this the standard way to handle it?


回答1:


AutobahnPython allows you to turn on sending tracebacks in WAMP error messages:

class MyComponent(ApplicationSession):
   def __init__(self, config = None):
      ApplicationSession.__init__(self, config)
      self.traceback_app = True


来源:https://stackoverflow.com/questions/27999685/logging-wamp-worker-trace-back-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!