def singleton(cls):
    """
    Wrapper that creates singleton instance of class that it is fed.

    Returns:
        any: Singleton instance of class.
    """
    instances = {}
    lock = threading.Lock()

    @wraps(cls)
    def wrapper(*args, **kargv):
        if cls not in instances:
            with lock:
                if cls not in instances:
                    instances[cls] = cls(*args, **kargv)
        return instances[cls]
    return wrapper
Wrapper that creates singleton instance of class that it is fed.

Returns:
any: Singleton instance of class.
towhee/utils/singleton.py