route_policy to choose a runtime for each command line with a script
or a function. Here, monty runs python3 in-process, while docker runs
it in a container with your packages. Start the Docker container
my-box with /jobs/train.py and its dependencies before using this excerpt:
route.py
python3 /jobs/train.py runs in the container; cat data.csv | python3 -c ... stays on monty.
Input and answers
A runtime routing script is a policy program shared by every session. It reads the samectx a program gets at pre_execute:
the line, each of its commands with its words and resolved paths, and
the session. It prints its answer:
A program that exits non-zero, runs past 10 seconds, or prints anything
else fails the line with a routing error. It runs on its own runtime,
monty unless the block names one, as
a profile’s programs do.
In code,
route_policy= takes the same block with a ScriptSource, or
a plain function, sync or async, returning a runtime name or None:
Admit, then route
Runtime selection happens atpre_execute, before commands run.
Mirage checks route_policy first, then any policies defined in code.
These policies can also choose a runtime or refuse a command line:
$( ),
eval, source, xargs) keep the outer line’s placement.
ws.explain(line) shows each placement answer and each command’s
runtime. The caller’s runtime= argument places the line itself.