pyvider
2026-03-22
Lazy provider initialization — RPC server starts before discovery completes
2 files · 123+ · 29-
Lazy background initialization in provider server startup
1 file changed
provide_command.pyRefactored _run_provider_server() to fire component discovery as an asyncio background task. Added initialize_and_register_provider() coroutine that awaits discovery then instantiates and registers providers in the hub. Server.serve() now starts before initialization completes. Removed premature synchronous _ensure_components_discovered() call from provide_cmd().
- Component discovery is now launched as asyncio.create_task() rather than awaited synchronously. A new initialize_and_register_provider() coroutine awaits the discovery task, instantiates providers, and registers the primary provider in the hub — all while the RPC server is already listening. A single await asyncio.sleep(0) yields control so background tasks start before server.serve() blocks the event loop.
decouple
behavioral
1 file
provide_command.py
- Removed the blocking _ensure_components_discovered() call and _handle_discovery_errors() from provide_cmd(). Discovery errors are now surfaced asynchronously during background initialization rather than blocking the CLI entry point.
deprecate
behavioral
1 file
provide_command.py
ProviderHandler resolves provider lazily from hub
1 file changed
handler.pyMade _provider field optional (default=None); added _resolved_provider cache; added _ensure_provider_ready() async method that fetches the provider from the hub on first RPC request. _delegate() calls _ensure_provider_ready() before dispatching.
- ProviderHandler no longer requires the provider at construction time. _ensure_provider_ready() checks a local cache first, then falls back to hub.get_component(‘singleton’, ‘provider’). If the provider is not yet registered (initialization still in progress), it waits 100ms and retries once before raising RuntimeError.
interface
behavioral
1 file
handler.py