uactor¶
uActor module.
-
uactor.
DEFAULT_SERIALIZER
= 'pickle'¶ Default
multiprocessing.managers
serializer name foruactor
.New in version 0.1.1.
-
exception
uactor.
UActorException
[source]¶ Bases:
Exception
Base exception for uactor module.
New in version 0.1.0.
-
exception
uactor.
ProxyError
[source]¶ Bases:
uactor.UActorException
Exception for errors on proxy logic.
New in version 0.1.0.
-
exception
uactor.
AuthkeyError
[source]¶ Bases:
uactor.ProxyError
Exception raised when connecting to proxy with invalid authkey.
New in version 0.1.1.
-
class
uactor.
BaseProxy
(token, serializer, manager=None, authkey=None, exposed=None, incref=True, manager_owned=False)[source]¶ Bases:
multiprocessing.managers.BaseProxy
Base Proxy class.
This class implements a few workarounds around bugs found in
multiprocessing.managers.BaseProxy
by preventingBaseProxy._manager
from getting lost on both unserialization and process forking by recreating it on demand.New in version 0.1.0.
-
class
uactor.
ActorManager
(address: Optional[AddressType] = None, authkey: Optional[bytes] = None, serializer: str = 'pickle', *args, parent: Optional[ActorManager] = None, **kwargs)[source]¶ Bases:
multiprocessing.managers.BaseManager
Multiprocessing manager for uactor.
New in version 0.1.0.
-
property
process
¶ Get remote actor process if owned by this manager.
-
connect
()[source]¶ Connect to manager process.
- Raises
AuthkeyError – on actor process authkey rejection.
-
property
-
class
uactor.
ActorProxy
(token, serializer, manager=None, authkey=None, exposed=None, incref=True, manager_owned=False)[source]¶ Bases:
uactor.BaseProxy
Actor proxy base class.
Actors will inherit from this class to create custom implementations based on their declared configuration and interface.
New in version 0.1.0.
-
__enter__
(*args, **kwargs)[source]¶ Call
Actor.__enter__()
method.
-
__exit__
(*args, **kwargs)[source]¶ Call
Actor.__exit__()
method.When this proxy is the direct result from instancing the
Actor
class, calling this method will also result onActor.shutdown()
being called, finishing the actor process (like when callingActorProxy.shutdown()
).
-
shutdown
()[source]¶ Call
Actor.shutdown()
method.When the current process is responsible of initializing the actor, calling this method will also finish the actor process.
-
-
class
uactor.
Actor
(*args, **kwargs)[source]¶ Bases:
object
Actor base class for actor implementations to inherit from.
An actor represents a processing unit. During instantiation, a new actor process is be started, and the corresponding proxy is returned.
Actors also implement the context manager interface, and you can override both
Actor.__enter__()
andActor.__exit__()
to implement your own logic, but keep in mind they’re both specially handled and callingActorProxy.__exit__()
will also terminate the process (just like callingActorProxy.shutdown()
).New in version 0.1.0.
-
manager_class
¶ ActorManager
subclass used to initialize the actor process.Whatever is defined here, will be subclassed during actor class initialization to apply the declared actor configuration.
alias of
ActorManager
-
proxy_class
¶ ActorProxy
subclass used to initialize the actor proxy.Whatever is defined here, will be subclassed during actor class initialization to apply the declared actor configuration.
alias of
ActorProxy
-
_options_
: Mapping[str, Any] = {}¶ Option
dict
will be passed toActor.manager_class
.This options mapping is passed to
Actor.manager_class
duringActor
instantiation.
-
_exposed_
: Optional[Tuple[str]] = ('__enter__', '__exit__', 'shutdown')¶ tuple
containing then list of method/properties will be exposed.Class inheritance will be honored when using this attribute.
-
_proxies_
: Mapping[str, Type[uactor.BaseProxy]] = {'Array': <class 'uactor.Proxy[Array]'>, 'AsyncResult': functools.partial(<function rebuild_autoproxy>, proxytype=<function AutoProxy>), 'Barrier': <class 'uactor.Proxy[Barrier]'>, 'BoundedSemaphore': <class 'uactor.Proxy[BoundedSemaphore]'>, 'Condition': <class 'uactor.Proxy[Condition]'>, 'Event': <class 'uactor.Proxy[Event]'>, 'Iterator': <class 'uactor.Proxy[Iterator]'>, 'JoinableQueue': functools.partial(<function rebuild_autoproxy>, proxytype=<function AutoProxy>), 'Lock': <class 'uactor.Proxy[Lock]'>, 'Namespace': <class 'uactor.Proxy[Namespace]'>, 'Pool': <class 'uactor.Proxy[Pool]'>, 'Queue': functools.partial(<function rebuild_autoproxy>, proxytype=<function AutoProxy>), 'RLock': <class 'uactor.Proxy[RLock]'>, 'Semaphore': <class 'uactor.Proxy[Semaphore]'>, 'Value': <class 'uactor.Proxy[Value]'>, 'auto': functools.partial(<function rebuild_autoproxy>, proxytype=<function AutoProxy>), 'dict': <class 'uactor.Proxy[dict]'>, 'list': <class 'uactor.Proxy[list]'>}¶ Proxy
dict
of typeid keys andBaseProxy
values.Proxies defined here will be registered at
Actor.manager_class
and will be made available from within the actor process.
-
_method_to_typeid_
: Mapping[str, str] = {'__enter__': 'actor'}¶ Configuration
dict
of method name keys and typeid values.Including a method with an typeid here will result on the corresponding proxy to be returned when called from an
ActorProxy
instance.
-
__exit__
(exc_type: Type[Exception], exc_val: Exception, exc_tb: traceback) → Optional[bool][source]¶ Leave context.
Method
uactor.Actor.shutdown()
will be called after this one when the context manager interface is used on the owner process.
-
shutdown
()[source]¶ Perform shutdown work before the process dies (stub).
This method will be called by explicit
ActorProxy.shutdown()
calls, even if no real process shutdown is involved (ie. with remote proxy connections), enabling implementing remote shutdown logic here (ie. breaking a mainloop).This method will be also called after
Actor.__exit__()
when the owner process uses theActorProxy
context manager interface.
-
classmethod
connect
(address: Union[Tuple[str, int], str, bytes, int], authkey: bytes, serializer: str = 'pickle', capture: Sequence[Union[Tuple[str, int], str, bytes, int]] = ()) → TActorProxy[source]¶ Get actor proxy instance connected to address.
- Parameters
address – actor process connection address
authkey – authentication secret key
serializer – serializer name
capture – iterable of additional addresses will be handled with this connection.
New in version 0.1.1.
-
-
uactor.
proxy
(value: Any, typeid: str = 'auto', serializer: str = 'pickle') → uactor.BaseProxy[source]¶ Create serialized proxy from given value and typeid (defaults to auto).
This function can be only used from inside the actor process.
New in version 0.1.0.
-
uactor.
typeid
(proxy: uactor.BaseProxy) → str[source]¶ Get typeid from given proxy object.
New in version 0.1.0.