utils.singleton — Singleton

class ievv_opensource.utils.singleton.Singleton[source]

Bases: object

Implements the singleton pattern.

Example

Create a singleton class:

class MySingleton(Singleton):
    def __init__(self):
        super().__init__()
        self.value = 0

    def add(self):
        self.value += 1

Use the singleton:

MySingleton.get_instance().add()
MySingleton.get_instance().add()
print(MySingleton.get_instance().value)

Ensures there is only one instance created. Make sure to use super() in subclasses.

classmethod get_instance()[source]

Get an instance of the singleton.