PyMpActor

The class is specific implementation of Actor class using Python Multiprocessing backend.

The PyMpActor implements 2 internal methods:

  • __getattr__() – transmits an access responsibility to the methods of native Python Multiprocessing Actor, held by this class, to PyMpActorMethod class.

  • _remote() – creates native Python Multiprocessing Actor object to be held by this class.

API

class unidist.core.backends.pymp.actor.PyMpActor(cls, num_cpus, resources)

The class implements the interface in Actor using Python Multiprocessing backend.

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

  • num_cpus (int) – The number of CPUs to reserve for the lifetime of the actor.

  • resources (dict) – Custom resources to reserve for the lifetime of the actor.

_remote(*args, num_cpus=None, resources=None, **kwargs)

Create actor class, specific for Python Multiprocessing backend, from self._cls.

Parameters:
  • *args (iterable) – Positional arguments to be passed in self._cls class constructor.

  • num_cpus (int, optional) – The number of CPUs to reserve for the lifetime of the actor.

  • resources (dict, optional) – Custom resources to reserve for the lifetime of the actor.

  • **kwargs (dict) – Keyword arguments to be passed in self._cls class constructor.

Return type:

PyMpActor

PyMpActorMethod

The class is specific implementation of ActorMethod class using Python Multiprocessing backend.

The PyMpActorMethod implements internal method _remote() that is responsible for calls of native Python Multiprocessing Actor class methods.

API

class unidist.core.backends.pymp.actor.PyMpActorMethod(cls, method_name)

The class implements the interface in ActorMethod using Python Multiprocessing backend.

Parameters:
  • cls (unidist.core.backends.pymp.core.Actor) – An actor class from which method method_name will be called.

  • method_name (str) – The name of the method to be called.

_remote(*args, num_returns=None, **kwargs)

Execute self._method_name in a worker process.

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

  • num_returns (int, optional) – Number of results to be returned. If it isn’t provided, self._num_returns will be used.

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

Returns:

Type of returns depends on num_returns value:

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

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

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

Return type:

ObjectRef, list or None