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, target_class=None)[source]

Broadcast message to all actors of the specified target_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()[source]

Get ActorRef for all running actors.

Returns:list of pykka.ActorRef
classmethod get_by_class(actor_class)[source]

Get ActorRef for all running actors of the given class, or of any subclass of the given class.

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)[source]

Get ActorRef for 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)[source]

Get an actor by its universally unique URN.

Parameters:actor_urn (string) – actor URN
Returns:pykka.ActorRef or None if not found
classmethod register(actor_ref)[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=True, timeout=None)[source]

Stop all running actors.

block and timeout works as for ActorRef.stop().

If block is True, 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)[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