nustack

kernel

Kernel ops: run planes, interrupt and kill them, run and interrupt their cells.

Module nuspace.ops.kernel.

Kernel ops: run planes, interrupt and kill them, run and interrupt their cells.

The store is the transport (D1): these write intents only. plane_run and cell_run write new records into the live indexes, the interrupts set interrupt_requested, plane_kill sets termination_requested. The kernel, in the host where the backends live, sees the records and makes them true, and it and the backends write every effect. So every op here is safe from any process holding the store, a service on a worker included.

Every op is O(1) or O(k), k being what is live of what it asks about: a plane's live runs are its planes_running, a run's live cell runs its cells_running, its live workers its workers_running, never runs nor all of running. A cell's newest cell run in a plane run is a point read of the run's latest (latest), never a walk of its cells, which grows with every reload.

NameCallMeaning
HereWhere a cell run's body runs: the ids the kernel holds for it in a frame.
cell_interruptops.cell_interrupt(run_id, cell_run_id)Ask a cell run to stop. A no-op when it is not live. One commit.
cell_runops.cell_run(run_id, cell_id, by='')Run a cell inside a live plane run: a new cell run, beside any other of it. One commit.
cell_runsops.cell_runs(run_id, live=False)A plane run's cell runs as dicts with their id, oldest first. Bare read.
envops.env(name)An env spec: the name a factory was registered under, then its args.
latestops.latest(run_id, cell_id)A cell's newest cell run in a plane run, live or ended, "" when it has none. Bare read.
plane_interruptops.plane_interrupt(run_id)Ask every live cell run of a plane run to stop. One commit.
plane_killops.plane_kill(run_id)Tear a plane run down: its backend kills whatever runs it. One commit.
plane_runops.plane_run(plane_id, by='', envs=(), into=None)Run a plane: a new plane run with a cell run per cell, in order. One commit.
plane_stopops.plane_stop(run_id, grace=10.0)Interrupt a plane run, then kill it if it is still running after grace seconds.
runops.run(run_id)One plane run by id, live or ended, whole: every cell run under cells, every worker. Bare read.
runsops.runs(plane=None)The live plane runs as dicts with their id, oldest first. Bare read.
workersops.workers()The live workers as dicts with their id, oldest first. Bare read.

Here

Where a cell run's body runs: the ids the kernel holds for it in a frame.

Path nuspace.ops.Here.

The kernel opens a frame over this Shape around every cell run's body, so a program and its envs read these, eg Here.plane, and never set them.

Slots

NameKindTypeConfigPath
planerefStrRefnuspace.ops.Here.plane
cellrefStrRefnuspace.ops.Here.cell
runrefStrRefnuspace.ops.Here.run
cell_runrefStrRefnuspace.ops.Here.cell_run

Undocumented: example.

cell_interrupt

Ask a cell run to stop. A no-op when it is not live. One commit.

ops.cell_interrupt(run_id, cell_run_id)

Path nuspace.ops.cell_interrupt. Defined on nuspace.ops.kernel, bound as a function. Builds nu.Nu.

Cooperative: its body watches interrupt_requested and ends itself interrupted. There is no cell kill: a backend may not be able to kill one cell alone, so kill is a plane op.

Arguments

NameTypeDefaultMeaning
run_idnu.StrArg
cell_run_idnu.StrArg

Undocumented: example.

cell_run

Run a cell inside a live plane run: a new cell run, beside any other of it. One commit.

ops.cell_run(run_id, cell_id, by='')

Path nuspace.ops.cell_run. Defined on nuspace.ops.kernel, bound as a function. Builds nu.Nu.

The new cell run is the cell's latest in the run, where a caller reads it. Nothing is written when the plane run is not live or the cell is not on its plane.

Arguments

NameTypeDefaultMeaning
run_idnu.StrArg
cell_idnu.StrArg
bynu.StrArg''

Undocumented: example.

cell_runs

A plane run's cell runs as dicts with their id, oldest first. Bare read.

ops.cell_runs(run_id, live=False)

Path nuspace.ops.cell_runs. Defined on nuspace.ops.kernel, bound as a function. Builds nu.List.

Every one it ever had, or with live only those in cells_running. Minted ids sort by creation, so sorted is oldest first.

Arguments

NameTypeDefaultMeaning
run_idnu.StrArg
liveboolFalse

Undocumented: example.

env

An env spec: the name a factory was registered under, then its args.

ops.env(name)

Path nuspace.ops.env. Defined on nuspace.ops.kernel, bound as a function. Builds list[str].

Plain data, so it is stored on the run (Run.envs) and anyone can run the plane the same way again.

Arguments

NameTypeDefaultMeaning
namestr

Undocumented: example.

latest

A cell's newest cell run in a plane run, live or ended, "" when it has none. Bare read.

ops.latest(run_id, cell_id)

Path nuspace.ops.latest. Defined on nuspace.ops.kernel, bound as a function. Builds nu.Str.

A point read of the run's latest: O(1) however many times the cell was reloaded or restarted in it.

Arguments

NameTypeDefaultMeaning
run_idnu.StrArg
cell_idnu.StrArg

Undocumented: example.

plane_interrupt

Ask every live cell run of a plane run to stop. One commit.

ops.plane_interrupt(run_id)

Path nuspace.ops.plane_interrupt. Defined on nuspace.ops.kernel, bound as a function. Builds nu.Nu.

Once they have, cells_running is empty and the run ends.

Arguments

NameTypeDefaultMeaning
run_idnu.StrArg

Undocumented: example.

plane_kill

Tear a plane run down: its backend kills whatever runs it. One commit.

ops.plane_kill(run_id)

Path nuspace.ops.plane_kill. Defined on nuspace.ops.kernel, bound as a function. Builds nu.Nu.

Not cooperative: its live cell runs end killed without a say. A no-op when the run is not live.

Arguments

NameTypeDefaultMeaning
run_idnu.StrArg

Undocumented: example.

plane_run

Run a plane: a new plane run with a cell run per cell, in order. One commit.

ops.plane_run(plane_id, by='', envs=(), into=None)

Path nuspace.ops.plane_run. Defined on nuspace.ops.kernel, bound as a function. Builds nu.Nu.

The run takes the plane's backend prop as it is now. A plane with no cells makes a run the kernel ends at once. A plane with no backend makes a run the kernel ends failed, the error saying so: there is no default.

Arguments

NameTypeDefaultMeaning
plane_idnu.StrArgThe plane.
bynu.StrArg''Who asked, eg nav.
envsSequence[Sequence[str]] | nu.Nu()Env specs its cells run inside, outermost first, each env(name, *args).
intonu.Ref | NoneNoneSet to the run id in the commit, "" when the plane is missing, for a caller that needs it: the record does not say which run this call made. A retried commit sets it again, so it names the run that landed.

Undocumented: example.

plane_stop

Interrupt a plane run, then kill it if it is still running after grace seconds.

ops.plane_stop(run_id, grace=10.0)

Path nuspace.ops.plane_stop. Defined on nuspace.ops.kernel, bound as a function. Builds nu.Nu.

Two intents, written as they fall due. Returns once the run has ended, or once the kill is asked for: a caller waits grace at most.

Arguments

NameTypeDefaultMeaning
run_idnu.StrArg
gracenu.FloatArg10.0

Undocumented: example.

run

One plane run by id, live or ended, whole: every cell run under cells, every worker. Bare read.

ops.run(run_id)

Path nuspace.ops.run. Defined on nuspace.ops.kernel, bound as a function. Builds nu.Dict.

The one read that walks a run's history, for inspecting it: O(what the run ever had). Nothing that runs on repeat reads it.

Arguments

NameTypeDefaultMeaning
run_idnu.StrArg

Undocumented: example.

runs

The live plane runs as dicts with their id, oldest first. Bare read.

ops.runs(plane=None)

Path nuspace.ops.runs. Defined on nuspace.ops.kernel, bound as a function. Builds nu.List.

Live is running, so this reads in the time of what is live, its workers the live ones. With plane, that plane's live runs only. A run's cell runs are cell_runs; an ended run is read by id with run.

Arguments

NameTypeDefaultMeaning
planenu.StrArg | NoneNone

Undocumented: example.

workers

The live workers as dicts with their id, oldest first. Bare read.

ops.workers()

Path nuspace.ops.workers. Defined on nuspace.ops.kernel, bound as a function. Builds nu.List.

handle is the backend's own, not for reading into.

Undocumented: example.

On this page