Registry / pysingleton

pysingleton

JSON →
library0.2.1pypypi✓ verified 85d ago

A minimal Python library providing a @singleton decorator to turn classes into singletons. Version 0.2.1, released Oct 2014. It is in maintenance mode with rare updates.

pip install pysingleton
INSTALL
IMPORT
SIG · PYSINGLETON
P
pysingleton
pythonv0.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

singleton
from singleton import singleton
from pysingleton import singleton

Apply @singleton to a class to ensure only one instance exists.

from pysingleton import singleton @singleton class MyClass: pass a = MyClass() b = MyClass() assert a is b print("Singleton works")
Debug
Known issues
gotchaLocking in __init__: The singleton decorator does not protect against concurrent instantiation. In multithreaded environments, __init__ may be called multiple times.
fix
Add a threading lock inside the class's __new__ method or use a thread-safe singleton pattern.
affects: all
gotchaSubclassing singletons: Subclassing a singleton class may lead to unexpected behavior. The subclass is not automatically a singleton.
fix
Avoid subclassing singletons; apply @singleton to each class individually.
affects: all
deprecatedPython 2 support: The library was built for Python 2 and may have compatibility issues with Python 3 (e.g., metaclass syntax).
fix
Use Python 3 compatible libraries like 'singledispatch' or custom metaclass for production code.
affects: 0.2.1
Upgrade
Version history
0.2.1latest on PyPI · released Apr 4, 2017
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
pysingleton — pip install pysingleton · libregistry