pattern-singleton 1.2.0

Last updated:

0 purchases

pattern-singleton 1.2.0 Image
pattern-singleton 1.2.0 Images
Add to Cart

Description:

patternsingleton 1.2.0

Description
Singleton is a creational design pattern that lets you ensure that a class has only one instance, while providing a global access point to this instance.
This implementation of Singleton Design Pattern is based on metaclass method.

Free software: MIT license
But I would appreciate a star on GitHub



Multithreaded
This method provide proper handling for multi-thread environment by closing public threading lock while creating instance of Singleton subclass.


Installation
Just use (No other package is needed):
$ pip install pattern-singleton


Example Usage
from pattern_singleton import Singleton


class Example(metaclass=Singleton):
def __init__(self):
self.variable = 1


if __name__ == '__main__':
example_01 = Example()
example_02 = Example()

print(example_01.variable) # displays 1
print(example_02.variable) # displays 1

example_01.variable = 2 # changes value for every instance of Example class

print(example_01.variable) # displays 2
print(example_02.variable) # displays 2

Credits
This package was created by Marcin Mysliwiec with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.