⚠️ Global State in Widget Manager
[!warning] Thread Safety Issue
Module-level lists for widget tracking are not thread-safe and hard to test in isolation.
Current Issue:
# manager.py
__widgets = [] # Module-level global
__excluded_widgets = []
Problems:
- Not thread-safe (Qt can be multi-threaded)
- Hard to test in isolation
- No clear ownership or lifecycle
- Implicit coupling
[!example] Recommended Solution
Refactor to singleton or instance-managed registry
class WidgetRegistry:
"""Thread-safe widget registry with clear lifecycle"""
_instance = None
def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)
cls._instance._widgets = []
cls._instance._excluded = []
cls._instance._lock = threading.Lock()
return cls._instance
def register(self, widget, **kwargs):
with self._lock:
# ... safe registration
# Usage
registry = WidgetRegistry()
registry.register(my_widget)
Current Issue:
Problems: