Skip to content

Loading search…

中文

entries

Start code as a unit of its own: spawn, wait, cancel, send, read its output so far, with a priority; claim and unclaim channels.

  • Layer: base
  • Needs: –
  • Requires: –
  • Conflicts with: –
  • Never dropped: no
  • Mixin: skills.entries:Entries
  • Manifest: skills/entries/skill.toml
def spawn(fn, name=None, claims=None, priority=None, restart=False, until=None)

Run fn() at the same time as this code, as a unit of its own, and return its handle: .wait(timeout=None) returns what fn returned (raises its failure, an ENTRY_FAILED event; None when it was cancelled or the timeout passed), .cancel() ends it, .send(message) gives it a message that its code reads with receive(), .output(chars=2000) is what it has printed so far, .state() says how it stands, .status is running, done, failed or cancelled. name labels it (default: fn’s name). priority: what it holds the embodiment with (default: that of the unit that starts it); a unit of higher priority ends a lower unit’s execution where it is, with the event PREEMPTED and what it had done, and holds the environment until it ends; the model is told at once. With restart=True the lower call is started again when the higher unit is over, instead. Units of equal priority take turns, in the order they start. claims names the channels it uses where the embodiment declares channels: it has them until it ends, and what it held on them is let go then; one another unit has makes it fail at once with a CHANNEL_CONFLICT event. The unit is the model’s: it and the reflexes it sets go on after the program that started it, and end with the model. A unit that fails goes to whoever waits for it, else to a reflex that answers ENTRY_FAILED; the model hears of every unit’s end. until: what the unit is for, a condition of the view that holds when its work is done; its end says whether it held (.ok).

def receive(timeout=None)

The oldest message sent to the entry this code runs in (handle.send), waiting at most timeout seconds for one (None: as long as it takes); None when none came.

def entries(running=True)

The handles of the units started so far (only those running, unless running is False), oldest first; each has .id, .state(), .output(), .wait(), .cancel(), .send(); a program the model wrote is one of them (.cell is its number); a sub-agent’s (delegate) has .agent.

def output_of(unit, chars=2000)

What the unit unit (its id, such as “e27”, or its handle) has printed so far: the last chars characters (at most 30000), while it runs or after it ended. Reading takes nothing away: the unit’s result still has the whole output when it ends. “” when it has printed nothing.

def claim(*channels)

Claim channels for the entry this code runs in until it unclaims them or ends; no other entry may use them meanwhile, its own entries may. True; when one is another entry’s, a CHANNEL_CONFLICT event goes to this entry’s handlers and up (False when a handler took it).

def unclaim(*channels)

Let go of channels (none named: all this entry has): its claims, and the keys and buttons it holds down on them.

Also in the namespace: channels (constants and names the skill’s exports(session) provides).

From the workspace prompt pack, with the core skills enabled:

entries(): the handles of the units that run, your programs among them, each with its
output_of(unit, chars=2000): what a unit (its id or its handle) has printed so far, the
unclaim(*channels) lets them go, channels() says who has each. Reaching for a channel
channels it took: spawn(..., claims=[...]) or claim(*channels) takes them,