Singleton

hivecore.patterns.singleton(class_: type) object

A decorator used to turn a class into a Singleton. This makes it so that if a class has already been instanciated one, that instance will be returned instead of a second one.

Parameters:

class (Class) – A class to apply the singleton to. Applied as a Decorator.

Returns:

Singleton instance of that Class.

Return type:

Object

Example

from hivecore.decorator import singleton

@singleton
class my_class:
    def __init__(self):
        my_attr = None