Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /dislovelhl_enhanced-agent-bus /bus /singleton.py
| """ | |
| Singleton pattern for global EnhancedAgentBus instance. | |
| Constitutional Hash: 608508a9bd224290 | |
| """ | |
| from __future__ import annotations | |
| import threading | |
| from typing import TYPE_CHECKING, Any, Callable, cast | |
| if TYPE_CHECKING: | |
| from .core import EnhancedAgentBus | |
| # Thread-safe singleton pattern for global agent bus | |
| _default_bus: EnhancedAgentBus | None = None | |
| _bus_lock = threading.Lock() | |
| def get_agent_bus(**kwargs: Any) -> EnhancedAgentBus: | |
| """Get the global agent bus instance (thread-safe). | |
| Uses double-checked locking pattern for thread safety. | |
| Note: kwargs are only used on first initialization. | |
| """ | |
| global _default_bus | |
| if _default_bus is None: | |
| with _bus_lock: | |
| # Double-checked locking pattern | |
| if _default_bus is None: | |
| from .core import EnhancedAgentBus | |
| bus_factory = cast(Callable[..., EnhancedAgentBus], EnhancedAgentBus) | |
| _default_bus = bus_factory(**kwargs) | |
| return _default_bus | |
| def reset_agent_bus() -> None: | |
| """Reset the global agent bus instance (thread-safe).""" | |
| global _default_bus | |
| with _bus_lock: | |
| _default_bus = None | |
Xet Storage Details
- Size:
- 1.17 kB
- Xet hash:
- 4a816fcbb60846ee14537da4972d708bfb00e62df8c29f606bde1e02f383c37b
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.