Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tornado websocket处理程序未捕获异常_Python_Tornado - Fatal编程技术网

Python tornado websocket处理程序未捕获异常

Python tornado websocket处理程序未捕获异常,python,tornado,Python,Tornado,我试图在我的WebSocketHandler中捕获未捕获的异常。但是Tornado没有与HTTP RequestHandler相同的异常处理接口 在上面的源代码中,这里似乎捕获并记录了异常: def _run_callback(self, callback, *args, **kwargs): """Runs the given callback with exception handling. On error, aborts the websocket connection

我试图在我的WebSocketHandler中捕获未捕获的异常。但是Tornado没有与HTTP RequestHandler相同的异常处理接口

在上面的源代码中,这里似乎捕获并记录了异常:

def _run_callback(self, callback, *args, **kwargs):
    """Runs the given callback with exception handling.

    On error, aborts the websocket connection and returns False.
    """
    try:
        callback(*args, **kwargs)
    except Exception:
        app_log.error("Uncaught exception in %s",
                      self.request.path, exc_info=True)
        self._abort()

有没有更好的方法来捕获
WebSocketHandler
中的异常,而不是对处理程序进行黑客攻击并对实现上述方法的
WebSocketProtocol
进行子类化和重写
WebSocketProtocol.\u run\u callback
是当前从基类执行此操作的最佳方法。但是,由于对该方法进行子类化和重写很麻烦,因此最好在应用程序级别处理它,直到。要么用一个大的try/except块包装您的所有回调,要么如果您有足够多的回调,这会让人恼火,您可以创建自己的异常捕获装饰器