Actor

Python Multiprocessing Actor class is intended to transform a user-defined class to the class shared between processes (using multiprocessing.managers.BaseManager), which methods will be executed in a separate Python Multiprocessing Worker.

API

class unidist.core.backends.pymp.core.actor.Actor(cls, *args, **kwargs)

Actor-class to execute methods of wrapped class in a separate worker.

Parameters:
  • cls (object) – Class to be an actor class.

  • *args (iterable) – Positional arguments to be passed in cls constructor.

  • **kwargs (dict) – Keyword arguments to be passed in cls constructor.

Notes

Python multiprocessing manager-class will be created to wrap cls. This makes cls class object shared between different workers. Manager-class starts additional process to share class state between processes.

Methods of cls class object are executed in the worker, grabbed from a workers pool.

submit(task)

Execute task asynchronously in the worker grabbed by this actor.

Parameters:

task (unidist.core.backends.pymp.core.process_manager.Task) – Task object holding callable function.

ActorMethod

The ActorMethod class is a wrapper over the method of the shared between processes class, stored in Python Multiprocessing Actor. Method submit() wraps a method of the shared between processes class object to Task and adds it to task queue of Python Multiprocessing Worker, used by Python Multiprocessing Actor.

API

class unidist.core.backends.pymp.core.actor.ActorMethod(cls_obj, actor, method_name, obj_store)

Class is responsible to execute method_name of cls_obj in the separate worker-process of actor object.

Parameters:
submit(*args, num_returns=1, **kwargs)

Execute self._method_name asynchronously in the worker of self._actor.

Parameters:
  • *args (iterable) – Positional arguments to be passed in the self._method_name method.

  • num_returns (int, default: 1) – Number of results to be returned from self._method_name.

  • **kwargs (dict) – Keyword arguments to be passed in the self._method_name method.

Returns:

Type of returns depends on num_returns value:

  • if num_returns == 1, DataID will be returned.

  • if num_returns > 1, list of DataID-s will be returned.

  • if num_returns == 0, None will be returned.

Return type:

unidist.core.backends.common.data_id.DataID, list or None