Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Supervisor API

The supervisor implementation lives in src/fauxtp/supervisor.py.

It provides a small, OTP-inspired supervisor that:

RestartStrategy

RestartStrategy

ChildSpec

ChildSpec

Fields:

Supervisor

Supervisor

Construction

Supervisor(children, strategy=..., registry=...) where:

If registry is None, the supervisor starts its own Registry as a child actor.

Restart semantics

The actor runtime reports exit reasons as:

The supervisor restarts only when the reason starts with "error:" (see Supervisor._should_restart()).

Example

import anyio

from fauxtp.actor.genserver import GenServer
from fauxtp.messaging import call
from fauxtp.registry import Registry
from fauxtp.supervisor import ChildSpec, RestartStrategy, Supervisor


class Worker(GenServer):
    async def init(self):
        return 0

    async def handle_call(self, request, _from, state):
        return state, state


async def main():
    async with anyio.create_task_group() as tg:
        registry = await Registry.start(task_group=tg)

        _sup_pid = await Supervisor.start(
            children=[
                ChildSpec(actor=Worker, name="worker-1"),
                ChildSpec(actor=Worker, name="worker-2"),
            ],
            strategy=RestartStrategy.ONE_FOR_ONE,
            registry=registry,
            task_group=tg,
        )

        worker_1 = await call(registry, ("get", "worker-1"))
        assert worker_1 is not None


anyio.run(main)

Notes: