async_task¶
Overview¶
This example shows how an asynchronous task runs within a Raya application. It showcases the process of task creation, execution, monitoring, and retrieval of task results before application termination.
Execution¶
To execute the example, use the following command:
python3 async_task/ --auto-run
This will automatically launch the application and start executing the asynchronous task.
Behavior¶
The application starts and initializes necessary parameters.
In the first execution cycle, an asynchronous task is created and starts running in the background.
The main loop logs messages at regular intervals while monitoring the background task.
The task logs messages periodically and completes execution after a defined number of iterations.
Once the task is finished, the application retrieves the task’s result and terminates.
Inputs¶
No user input is required; execution is automated.
Outputs¶
Log messages indicating the execution status of both the main loop and the asynchronous task.
A final log confirming that the task has finished execution and the application has terminated.
Example Output¶
During execution, the output logs follow this pattern:
[INFO] [timestamp] [pyraya.async_task]: Auto running the app
[INFO] [timestamp] [pyraya.async_task]: Task 1 created
[INFO] [timestamp] [pyraya.async_task]: Hello from loop: 0
[WARNING] [timestamp] [pyraya.async_task]: Hello from task: argument 0
...
[INFO] [timestamp] [pyraya.async_task]: Task 1 finished
[INFO] [timestamp] [pyraya.async_task]: App finished
Key Notes¶
The application continuously monitors the task’s status before proceeding with termination.
The execution flow ensures that asynchronous processing does not interfere with the main loop.
Proper task cleanup and retrieval mechanisms are in place before application shutdown.