nv_dfm_core.session.AsyncioDispatcher#
- class nv_dfm_core.session.AsyncioDispatcher(loop=None)[source]#
Dispatcher that schedules callbacks on an asyncio event loop.
Expects async callbacks. The callbacks will be scheduled to run on the specified event loop (or the current event loop if not specified). This enables callbacks to be executed in an async context even when dispatched from a background thread.
Note: AsyncioDispatcher only supports asynchronous callbacks. If you need to use sync callbacks, use DirectDispatcher instead.
Example
# Use current event loop (resolved lazily) session = Session(
federation_name=”my_fed”, homesite=”site1”, callback_dispatcher=AsyncioDispatcher()
)
# Use specific event loop loop = asyncio.get_event_loop() session = Session(
federation_name=”my_fed”, homesite=”site1”, callback_dispatcher=AsyncioDispatcher(loop=loop)
)
# With async callback async def my_async_callback(site, node, frame, place, data):
await process_data_async(data)
job = session.execute(pipeline, default_callback=my_async_callback)
- Parameters:
loop (asyncio.AbstractEventLoop | None)
- create_runner(default_callback=None, place_callbacks=None)[source]#
Create an _AsyncioRunner for event loop callback scheduling.
- Parameters:
default_callback (DfmDataCallback | None) – Fallback callback for tokens without a place-specific callback.
place_callbacks (dict[str, DfmDataCallback] | None) – Dictionary mapping place names to callbacks.
- Returns:
An _AsyncioRunner instance that schedules callbacks on the event loop.
- Raises:
ValueError – If any callback is synchronous (use DirectDispatcher instead).
- Return type:
- property loop: AbstractEventLoop#
Get the event loop (lazily resolved if not explicitly set).
- Returns:
The event loop to use for scheduling callbacks.