# 装饰类中函数的装饰器第一个参数是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