What happens during one run
This page follows one call to nr.run(task=my_task) from start to end.
1. The first run prepares the workers
The runner does nothing with Ray when it is created. At the first run it:
- reads its settings from the code, the Nornir configuration and the environment;
- connects to the Ray cluster, or starts a local Ray when no address is set;
- starts
workers_per_nodeworkers on each node that can run workers.
When one of these steps fails, the run fails before any host starts, and the error names the cause. Later runs in the same Python process use the same workers.
2. Each run checks the task and places the hosts
Before any host starts, the runner checks that the task function and its arguments can be
sent to another process. A task that cannot be sent fails the whole run with
TaskNotSerializableError. No host starts with a task that would fail on every worker.
The runner then replaces the workers that stopped since the last run and gives each host to a worker.
3. The worker runs the task for the host
For each host, the driver sends one call to the host's worker. The call holds:
- a copy of the host's inventory data, credentials included;
- the task function and its arguments;
- the Nornir configuration.
The worker runs your task with this copy of the host. When the task opens a connection, the connection starts from the worker's machine.
4. The results come back
While the task runs, the worker sends events to the driver: one when a subtask starts, one when a subtask ends, and one for each partial result. Your processors receive them on the driver, so progress output works as with the other runners.
At the end, the worker sends the final result. The driver adds the ray attribute to it, which
names the node and the worker that ran the host. See
Find where each host ran.
5. One host does not affect another
- A task that raises an exception on one host fails that host only. The exception in the host's result is the one your task raised.
- A worker that stops during a run fails the hosts it was running with
WorkerDiedError. The other hosts continue. - The runner does not run a failed host again. You decide whether to run the task again, for
example on
nr.filter(...)of the failed hosts.