flowno.core.event_loop.event_loop
Custom event loop implementation for Flowno’s asynchronous execution model.
This module provides a lightweight, cooperative multitasking event loop that handles: - Task scheduling and management - Sleeping/timing operations - Network socket operations - Asynchronous queue operations - Task joining and cancellation
The EventLoop class is the central component of Flowno’s asynchronous execution, implementing a command-based coroutine system similar to Python’s asyncio.
This can be used as a standalone event loop without the rest of the Flowno runtime.
- class flowno.core.event_loop.event_loop.EventLoop[source]
The core event loop implementation for Flowno’s asynchronous execution model.
Manages task scheduling, I/O operations, and synchronization primitives for the dataflow runtime.
- _handle_command(current_task_packet: tuple[Coroutine[Command, Any, Any], Any, Exception | None], command: Command) bool [source]
Handle the command yielded by the current task.
Returns True if the command was successfully handled.
- cancel(raw_task: Coroutine[Command, Any, Any]) bool [source]
Cancel a task.
- Parameters:
raw_task – The task to cancel.
- Returns:
True if the task was successfully cancelled; False if it was already finished or errored.
- handle_queue_close(queue: AsyncQueue[Any]) None [source]
Handle a queue being closed. Also resumes all tasks waiting on the queue with an appropriate exception.
- run_until_complete(root_task: Coroutine[Command, Any, _ReturnT], join: bool = False, wait_for_spawned_tasks: bool = True, _debug_max_wait_time: float | None = None) _ReturnT | None [source]
Run the event loop until the given root task is complete.
This method executes the main event loop, processing tasks, handling I/O operations, and managing task synchronization until the root task completes. It can optionally wait for all spawned tasks to finish as well.
- Parameters:
root_task (RawTask[Command, Any, _ReturnT]) – The coroutine task to execute as the root of the execution graph.
join (bool) – When True, returns the result value of the root task. When False, returns None regardless of the task’s result. If the task raises an exception and join=True, the exception is re-raised.
wait_for_spawned_tasks (bool) – When True, continue running the event loop until all tasks spawned by the root task have completed. When False, stop as soon as the root task completes.
_debug_max_wait_time (float | None) – Optional timeout value in seconds used for debugging. Limits how long the event loop will wait for network or sleeping operations.
- Returns:
- If join=True, returns the result of the root task (of type _ReturnT).
If join=False, returns None.
- Return type:
_ReturnT | None
- Raises:
RuntimeError – If the event loop exits without completing the root task when join=True.
Exception – Any exception raised by the root task is propagated if join=True.