No project description provided
Project description
WIP Singleton
About the project
A clean, transparent and easy to use python singleton wrapper.
Installation
TODO: once published:
pip install singleton2
Usage
Singleton definition:$$
from singleton import singleton
@singleton
class Counter:
def __init__(self, initial_counter):
self.counter = initial_counter
def inc(self):
self.counter += 1
Usage:
counter1 = Counter(1)
counter1.inc()
counter2 = Counter(1)
print(counter2.counter)
# >>> 2
Ensures that at most only one instance of the class exists at any point in time.
__init__
and __new__
of the original class get called only once: the first time
an instance is created. This instance will from then on be the singleton instance.
Every following call to the constructor of the wrapped class returns the singleton instance.
The wrapped class cannot have a class variable called _singleton
as that stores
the singleton instance. This will throw an error before execution begins.
Not thread safe during first initialization.
Roadmap
Contributing
License
Contact
Stephan Schmiedmayer
Acknowledgments
- TODO: APP lead & team members
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for better_singleton-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 036dd2bbd847c1785a9545961191559510d409fcef3b04e7a08f608dcbaa64d8 |
|
MD5 | 8fcd040305c658d66e0d6a25a27dc979 |
|
BLAKE2b-256 | 447ba071d02500eac9cbac5a8ae2e6b7ce86fc3b99afd442d201f82a453d2cd9 |