Registry
- class pykka.ActorRegistry[source]
Registry which provides easy access to all running actors.
Contains global state, but should be thread-safe.
- classmethod broadcast(message: Any, target_class: str | type[Actor] | None = None) None [source]
Broadcast
message
to all actors of the specifiedtarget_class
.If no
target_class
is specified, the message is broadcasted to all actors.- Parameters:
message (any) – the message to send
target_class (class or class name) – optional actor class to broadcast the message to
- classmethod get_all() list[ActorRef[Any]] [source]
Get all running actors.
- Returns:
list of
pykka.ActorRef
- classmethod get_by_class(actor_class: type[A]) list[ActorRef[A]] [source]
Get all running actors of the given class or a subclass.
- Parameters:
actor_class (class) – actor class, or any superclass of the actor
- Returns:
list of
pykka.ActorRef
- classmethod get_by_class_name(actor_class_name: str) list[ActorRef[Any]] [source]
Get all running actors of the given class name.
- Parameters:
actor_class_name (string) – actor class name
- Returns:
list of
pykka.ActorRef
- classmethod get_by_urn(actor_urn: str) ActorRef[Any] | None [source]
Get an actor by its universally unique URN.
- Parameters:
actor_urn (string) – actor URN
- Returns:
pykka.ActorRef
orNone
if not found
- classmethod register(actor_ref: ActorRef[Any]) None [source]
Register an
ActorRef
in the registry.This is done automatically when an actor is started, e.g. by calling
Actor.start()
.- Parameters:
actor_ref (
pykka.ActorRef
) – reference to the actor to register
- classmethod stop_all(*, block: Literal[True], timeout: float | None = None) list[bool] [source]
- classmethod stop_all(*, block: Literal[False], timeout: float | None = None) list[Future[bool]]
- classmethod stop_all(*, block: bool = True, timeout: float | None = None) list[bool] | list[Future[bool]]
Stop all running actors.
block
andtimeout
works as forActorRef.stop()
.If
block
isTrue
, the actors are guaranteed to be stopped in the reverse of the order they were started in. This is helpful if you have simple dependencies in between your actors, where it is sufficient to shut down actors in a LIFO manner: last started, first stopped.If you have more complex dependencies in between your actors, you should take care to shut them down in the required order yourself, e.g. by stopping dependees from a dependency’s
on_stop()
method.- Returns:
If not blocking, a list with a future for each stop action. If blocking, a list of return values from
pykka.ActorRef.stop()
.
- classmethod unregister(actor_ref: ActorRef[A]) None [source]
Remove an
ActorRef
from the registry.This is done automatically when an actor is stopped, e.g. by calling
Actor.stop()
.- Parameters:
actor_ref (
pykka.ActorRef
) – reference to the actor to unregister