类单例装饰器

def singleton(cls, *args, **kwargs):
    """类单例装饰器"""
    instance = {}

    def _singleton():
        if cls not in instance:
            instance[cls] = cls(*args, **kwargs)
        return instance[cls]
    return _singleton