问题
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