backtrader.mixins.singleton module¶
Singleton Mixin Module - Singleton pattern implementation.
This module provides the SingletonMixin class for implementing the singleton pattern without using metaclasses. This is part of the metaprogramming removal effort in backtrader.
- Classes:
SingletonMixin: Mixin class that implements the singleton pattern. ParameterizedSingletonMixin: Singleton mixin with parameter support. StoreBase: Base class for store singletons.
Example
Creating a singleton class: >>> class MyClass(SingletonMixin): … pass >>> a = MyClass() >>> b = MyClass() >>> assert a is b # True - same instance
- class backtrader.mixins.singleton.SingletonMixin[source]¶
Bases:
objectMixin class to implement singleton pattern using __new__ method.
This replaces the MetaSingleton metaclass pattern, providing the same functionality without using metaclasses. Each class that inherits from this mixin will maintain exactly one instance per class.
Thread-safe implementation using threading.Lock.
Features: - Thread-safe singleton creation - Per-class singleton instances (subclasses get their own instances) - Automatic cleanup when instances are garbage collected - Maintains compatibility with existing parameter systems
- class backtrader.mixins.singleton.ParameterizedSingletonMixin[source]¶
Bases:
SingletonMixinEnhanced singleton mixin that integrates with parameter systems.
This version is specifically designed to work with backtrader’s parameter system, maintaining compatibility with MetaParams functionality.
- backtrader.mixins.singleton.StoreBase¶
alias of
ParameterizedSingletonMixin