Singleton

Deprecated since version future: The singleton decorator will be moved to hivecore.patterns module in the future. Please update your imports accordingly.

hivecore.decorator.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 MyClass:
    def __init__(self):
        my_attr = None