rodario

rodario

A simple, redis-backed Python actor framework

Connection

By default, rodario will use a StrictRedis connection to localhost on the default port. If you wish to override this behavior, then replace the rodario.get_redis_connection method after import:

from redis import StrictRedis
import rodario
rodario.get_redis_connection = lambda: StrictRedis(host='1.2.3.4')

The Registry

class rodario.registry.Registry[source]

Actor registry class (singleton wrapper)

static __new__(prefix=None)[source]

Retrieve the singleton instance for Registry.

Parameters:prefix (str) – Optional prefix for redis key names
Return type:rodario.registry._RegistrySingleton
class rodario.registry._RegistrySingleton(prefix=None)[source]

Singleton for actor registry

__init__(prefix=None)[source]

Initialize the registry.

Parameters:prefix (str) – Optional prefix for redis key names
actors

Retrieve a list of registered actors.

Return type:set
exists(uuid)[source]

Test whether an actor exists in the registry.

Parameters:uuid (str) – UUID of the actor to check for
Return type:bool
get_proxy(uuid)[source]

Return an ActorProxy for the given UUID.

Parameters:uuid (str) – The UUID to return a proxy object for
Return type:rodario.actors.ActorProxy
register(uuid)[source]

Register a new actor.

Parameters:uuid (str) – The UUID of the actor to register
unregister(uuid)[source]

Unregister an existing actor.

Parameters:uuid (str) – The UUID of the actor to unregister

Actors and Proxies

class rodario.actors.Actor(uuid=None)[source]

Base Actor class

__init__(uuid=None)[source]

Initialize the Actor object.

Parameters:uuid (str) – Optionally-provided UUID
is_alive

Return True if this Actor is still alive.

Return type:bool
join(channel, func=None)[source]

Join this Actor to a pubsub cluster channel.

Parameters:
  • channel (str) – The channel to join
  • func (callable) – The message handler function
part(channel)[source]

Remove this Actor from a pubsub cluster channel.

Parameters:channel (str) – The channel to part
proxy()[source]

Wrap this Actor in an ActorProxy object.

Return type:rodario.actors.ActorProxy
start()[source]

Fire up the message handler thread.

stop()[source]

Kill the message handler thread.

class rodario.actors.ActorProxy(actor=None, uuid=None)[source]

Proxy object that fires calls to an actor over redis pubsub

__init__(actor=None, uuid=None)[source]

Initialize instance of ActorProxy.

Accepts either an Actor object to clone or a UUID, but not both.

Parameters:
_proxy(method_name, *args, **kwargs)[source]

Proxy a method call to redis pubsub.

This method is not meant to be called directly. Instead, it is used by the proxy’s self-generated methods to provide the proxy with the same public API as the actor it represents.

Parameters:
  • method_name (str) – The method to proxy
  • args (tuple) – The arguments to pass
  • kwargs (dict) – The keyword arguments to pass
Return type:

multiprocessing.Queue

proxyid = None

This proxy object’s UUID for creating unique channels

class rodario.actors.ClusterProxy(channel)[source]

Proxy object responsible for multiple actors

This class is meant to be inherited by child objects which can provide their own API methods for coordinating the Actors in their channel.

__init__(channel)[source]

Initialize instance of ClusterProxy.

Parameters:channel (str) – The cluster channel to use
_proxy(method_name, *args, **kwargs)[source]

Proxy a method call to redis pubsub.

Use this method in your child objects which inherit from ClusterProxy to provide the proxy with some representation of the public API for the Actors it represents.

Paramstr method_name:
 

The method to proxy

Parameters:
  • args (tuple) – The arguments to pass
  • kwargs (dict) – The keyword arguments to pass
Return type:

rodario.future.Future

Returns:

A Future whose first value is the number of expected responses

channel = None

Cluster channel

proxyid = None

This proxy object’s UUID for creating unique channels

class rodario.future.Future(queue)[source]

Custom response type for proxied method calls

__init__(queue)[source]

Initialize the Future by saving a reference to the Queue

Parameters:queue (multiprocessing.Queue) – The response queue to wrap
get(*args, **kwargs)[source]

Resolve and return the proxied method call’s value.

Return type:mixed
ready

Return True if the response value is available.

Return type:bool

Decorators

class rodario.decorators.DecoratedMethod(func, decorations=None, before=None, after=None)[source]

Generic decorated method

__init__(func, decorations=None, before=None, after=None)[source]

Wrap the given function.

Parameters:
  • func (function) – The function to wrap
  • decorations (set) – The decorator tags to attach
  • before (list) – The list of before-hook functions
  • after (list) – The list of after-hook functions
after = []

List of after-hook functions

before = []

List of before-hook functions

static decorate(func, decorations=None, before=None, after=None)[source]

Decorate the given function. If it is already a DecoratedMethod, it will be appended to rather than overwritten.

Parameters:
  • decorations (set) – The decorator tags to attach
  • before (list) – The list of before-hook functions
  • after (list) – The list of after-hook functions
Return type:

rodario.decorators.DecoratedMethod

Returns:

A DecoratedMethod wrapper around func

decorations = set([])

Set of decorator tags

rodario.decorators.singular(func)[source]

First-come, first-served cluster channel call. Needs some work; should accept parameters for context and expiry.

Parameters:func (function) – The function to wrap
Return type:rodario.decorators.DecoratedMethod

Exceptions

class rodario.exceptions.InvalidActorException[source]

Raised when a referenced actor does not exist

class rodario.exceptions.InvalidProxyException[source]

Raised when a proxy is not given a valid object to wrap

class rodario.exceptions.UUIDInUseException[source]

Raised during UUID registration if the UUID is already taken

class rodario.exceptions.RegistrationException[source]

Raised when actor registration fails

class rodario.exceptions.EmptyClusterException[source]

Raised when a message is passed to an empty cluster channel

Utilities

Utility module for rodario framework

rodario.util.acquire_lock(name, expiry=None, context=None, conn=None)[source]

Acquire a lock in redis.

Parameters:
  • name (str) – Name of the lock to acquire
  • expiry (int) – The duration of the lock (in seconds)
  • context (str) – The context to apply to the lock name
  • conn (redis.Connection) – The redis connection to use
Return type:

bool

Returns:

Whether or not the lock was acquired

Indices and tables