magscope.ipc#
Exceptions#
Base error for command registration problems. |
|
Raised when a command is registered more than once with incompatible metadata. |
|
Raised when a handler is missing for a registered command. |
|
Raised when dispatch is attempted for an unknown command. |
Classes#
Enum where members are also (and must be) strings |
|
Registry mapping IPC command types to their handlers and destinations. |
Functions#
|
Decorator to associate an IPC command type with a handler method. |
Yield command registrations declared on |
|
|
Return the payload of a command as keyword arguments. |
|
Create duplex pipes for each managed process. |
|
Send a command to all running, non-quitting processes. |
|
Drain a pipe until the paired quit event is set. |
Module Contents#
- class magscope.ipc.Delivery[source]#
Bases:
enum.StrEnumEnum where members are also (and must be) strings
- exception magscope.ipc.CommandRegistrationError[source]#
Bases:
RuntimeErrorBase error for command registration problems.
- exception magscope.ipc.CommandConflictError[source]#
Bases:
CommandRegistrationErrorRaised when a command is registered more than once with incompatible metadata.
- exception magscope.ipc.MissingCommandHandlerError[source]#
Bases:
CommandRegistrationErrorRaised when a handler is missing for a registered command.
- exception magscope.ipc.UnknownCommandError[source]#
Bases:
RuntimeErrorRaised when dispatch is attempted for an unknown command.
- class magscope.ipc.CommandSpec[source]#
- command_type: type[magscope.ipc_commands.Command][source]#
- class magscope.ipc.HandlerRegistration[source]#
- command_type: type[magscope.ipc_commands.Command][source]#
- magscope.ipc.register_ipc_command(command_type: type[magscope.ipc_commands.Command], *, delivery: Delivery = Delivery.DIRECT, target: str | None = None)[source]#
Decorator to associate an IPC command type with a handler method.
- magscope.ipc._collect_handler_registrations(cls: Type) Iterable[HandlerRegistration][source]#
Yield command registrations declared on
clsand its bases.
- magscope.ipc.command_kwargs(command: magscope.ipc_commands.Command) dict[str, object][source]#
Return the payload of a command as keyword arguments.
- class magscope.ipc.CommandRegistry[source]#
Registry mapping IPC command types to their handlers and destinations.
- _specs: dict[type[magscope.ipc_commands.Command], CommandSpec][source]#
- _handler_index: dict[tuple[str, str], type[magscope.ipc_commands.Command]][source]#
- register(*, command_type: type[magscope.ipc_commands.Command], handler: str, owner: Type, delivery: Delivery, target: str) None[source]#
Register a command handler.
- register_manager(manager: magscope.processes.ManagerProcessBase) None[source]#
Register all decorated command handlers on
manager.
- register_object(obj: object, *, target: str | None = None) None[source]#
Register decorated handlers on arbitrary objects (e.g., MagScope).
- route_for(command: magscope.ipc_commands.Command) CommandSpec[source]#
Return the route information for
command.
- handlers_for_target(target: str) dict[type[magscope.ipc_commands.Command], CommandSpec][source]#
Return handler specs applicable to
target.
- validate_targets(processes: Mapping[str, magscope.processes.ManagerProcessBase]) None[source]#
Ensure every command has a reachable target and handler.
- command_for_handler(owner: str, handler: str) type[magscope.ipc_commands.Command][source]#
Return the command type bound to
owner.handler.
- magscope.ipc.create_pipes(processes: Mapping[str, magscope.processes.ManagerProcessBase]) tuple[dict[str, multiprocessing.connection.Connection], dict[str, multiprocessing.connection.Connection]][source]#
Create duplex pipes for each managed process.
Returns a pair of dictionaries mapping process names to the parent and child pipe ends, respectively. The parent ends are intended to be owned by the coordinating
MagScopeinstance while the child ends are passed to individual manager processes.
- magscope.ipc.broadcast_command(command: magscope.ipc_commands.Command, *, pipes: Mapping[str, multiprocessing.connection.Connection], processes: Mapping[str, magscope.processes.ManagerProcessBase], quitting_events: Mapping[str, multiprocessing.synchronize.Event]) None[source]#
Send a command to all running, non-quitting processes.