python 装饰器进阶(待整合)
# 装饰类中函数的装饰器第一个参数是self
def connection_closed_handler(function):
    """Handle ConnectionClosedException."""
    @wraps(function)
    def _wrap(inst, *args, **kwargs):
        try:
            return function(inst, *args, **kwargs)
        except (ConnectionClosedException, WebSocketConnectionClosedException):
            inst.logger.warn("the connection lost. Resetting ...")
            inst.reset(args[1])
            return function(inst, *args, **kwargs)
    return _wrap
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号