v0.4.0 - run_on_main helper method
What's new
-
quiv.run_on_main(func, *args, **kwargs)— fire-and-forget helper that dispatches a callable onto the active Quiv instance's main event loop. Importable at module level (from quiv import run_on_main) and callable from anywhere in a task handler's call stack - no_progress_hookparameter to thread through intermediate functions.- Auto-detects whether the caller is already on the main loop's thread: sync targets run inline on-loop and async targets are scheduled via
main_loop.create_task. From a worker thread, sync targets dispatch viacall_soon_threadsafeand async targets viarun_coroutine_threadsafe. - The same helper works from a FastAPI route handler on the main loop and from inside a Quiv task — one utility shared between request and task code (e.g., a WebSocket broadcast whose connected-clients state lives on uvicorn's loop).
- Exceptions raised by the target are logged on the active Quiv's logger and swallowed, mirroring
_progress_hookand event-listener semantics.
See Running on the main event loop for the full walkthrough.
- Auto-detects whether the caller is already on the main loop's thread: sync targets run inline on-loop and async targets are scheduled via
Other changes
Quiv.start()now registers the instance as the process-level "active" Quiv (cleared byshutdown()) sorun_on_maincan resolve a target loop when called outside a task context. Multiple concurrent instances log a warning naming the most recently started instance as the winner for out-of-task callers.- Inside
_run_job, aContextVaris set to the runningQuivinstance for the duration of each handler invocation; this propagates into nested sync calls, the per-job async event loop, andasyncio.create_taskspawned inside an async handler.
Full Changelog: v0.3.5...v0.4.0