Threading Type

Actor

<See source>

class pyactor.thread.actor.Actor(url, klass, obj)

Actor is the instance of an object to which is possible to access and invoke its methods remotely. Main element of the model. The host is the one to create them (spawning -> see spawn()).

Parameters:
  • url (str.) – URL where the actor is running.
  • klass (class) – class type for the actor.
  • obj (klass) – instance of the klass class to attach to the actor.
is_alive()
Returns:(bool.) identifies the current state of the actor. True if it is running.
receive(msg)

The message received from the queue specifies a method of the class the actor represents. This invokes it. If the communication is an ASK, sends the result back to the channel included in the message as an ASK_RESPONSE.

If it is a FUTURE, generates a FUTURE_RESPONSE to send the result to the manager.

Parameters:msg – The message is a dictionary using the constants defined in util.py (pyactor.util).
run()

Creates the actor thread which will process the channel queue while the actor is_alive(), making it able to receive queries.

class pyactor.thread.actor.ActorRef(url, klass, channel=None)

ActorRef contains the main components of an actor. These are the URL where it is located, the communication Channel and the class of the actor as also the synchronous and asynchronous methods the class implements. When no channel is specified a new one will be created which is also the default procedure.

Note

This is a superclass of Actor and has no direct functionality.

class pyactor.thread.rpcactor.RPCDispatcher(url, host, mode)

This is the actor that will manage remote sends and receives with other hosts. Each host has one, configured depending on the scheme specified when created.

receive(msg)

The message received from the queue specifies a method of the class the actor represents. This invokes it. If the communication is an ASK, sends the result back to the channel included in the message as an ASK_RESPONSE.

If it is a FUTURE, generates a FUTURE_RESPONSE to send the result to the manager.

Parameters:msg – The message is a dictionary using the constants defined in util.py (pyactor.util).

Intervals

<See source>

pyactor.thread.intervals.interval_host(host, time, f, *args, **kwargs)

Creates an Event attached to the host that will execute the f function every time seconds.

See example in Sample 11 - Intervals

Parameters:
  • host (Proxy) – host proxy. Can be obtained from inside a class with self.host.
  • time (int) – seconds for the intervals.
  • f (func) – function to be called every time seconds.
  • args (list) – arguments for f.
Returns:

Event instance of the interval.

pyactor.thread.intervals.later(timeout, f, *args, **kwargs)

Sets a timer that will call the f function past timeout seconds.

See example in Sample 11 - Intervals

Returns:Timer
pyactor.thread.intervals.sleep(time)

Facade for the sleep function. Avoid using time.sleep.

Parameters:time (int) – time to sleep, in seconds. (Float for second divisions)

Parallel

<See source>

class pyactor.thread.parallels.ActorParallel(url, klass, obj)

Actor with parallel methods. Parallel methods are invoked in new threads, so their invocation do not block the actor allowing it to process many queries at a time. To avoid concurrence problems, this actors use Locks to guarantee its correct state.

get_lock()
Returns:Lock of the actor.
receive(msg)

Overwriting Actor.receive(). Adds the checks and features required by parallel methods.

Parameters:msg – The message is a dictionary using the constants defined in util.py (pyactor.util).
class pyactor.thread.parallels.ParallelAskWrapper(method, actor, lock)

Wrapper for ask methods that have to be called in a parallel way.

class pyactor.thread.parallels.ParallelTellWrapper(method, actor, lock)

Wrapper for tell methods that have to be called in a parallel way.

Future

<See source>

class pyactor.thread.future.Future(fid, future_ref, manager_channel)

Container for the result of an ask query sent asynchronously which could not be resolved yet.

Parameters:fid (str.) – future ID.
add_callback(method)

Attaches a method that will be called when the future finishes.

Parameters:method – A callable from an actor that will be called when the future completes. The only argument for that method must be the future itself from which you can get the result though future.:meth:`result()`. If the future has already completed, then the callable will be called immediately.

Note

This functionality only works when called from an actor, specifying a method from the same actor.

done()

Return True if the future finished executing.

exception(timeout=None)

Return a exception raised by the call that the future represents. :param timeout: The number of seconds to wait for the exception

if the future has not been completed. None, the default, sets no limit.
Returns:The exception raised by the call that the future represents or None if the call completed without raising.
Raises:TimeoutError: If the timeout is reached before the future ends execution.
result(timeout=None)

Returns the result of the call that the future represents.

Parameters:timeout – The number of seconds to wait for the result if the future has not been completed. None, the default, sets no limit.
Returns:The result of the call that the future represents.
Raises:TimeoutError: If the timeout is reached before the future ends execution.
Raises:Exception: If the call raises the Exception.
running()

Return True if the future is currently executing.

send_work()

Sends the query to the actor for it to start executing the work.

It is possible to execute once again a future that has finished if necessary (overwriting the results), but only one execution at a time.

set_exception(exception)

Sets the result of the future as being the given exception. Only called internally.

set_result(result)

Sets the return value of work associated with the future. Only called internally.

class pyactor.thread.future.FutureManager

A manager that controls the creation and execution of the futures in a host.

class pyactor.thread.future.FutureRef(fid, future_ref, manager_channel)
result(timeout=None)

Returns the result of the call that the future represents.

Parameters:timeout – The number of seconds to wait for the result if the future has not been completed. None, the default, sets no limit.
Returns:The result of the call that the future represents.
Raises:TimeoutError: If the timeout is reached before the future ends execution.
Raises:Exception: If the call raises the Exception.