wbia.web.futures_utils package¶
Submodules¶
wbia.web.futures_utils._base_actor module¶
-
class
wbia.web.futures_utils._base_actor.
Actor
[source]¶ Bases:
object
Base actor class.
Actors receive messages, which are arbitrary objects from their managing executor.
The main difference is that we expose an Actor class which can be inherited from and provides the executor classmethod. This creates an asynchronously maintained instance of this class in a separate thread/process
Example
>>> # DISABLE_DOCTEST >>> from concurrent.futures import ThreadActor >>> class MyActor(ThreadActor): >>> def __init__(self): >>> self.state = 0 >>> # >>> def handle(self, message): >>> self.state += message >>> return self.state >>> # >>> executor = MyActor.executor() >>> f = executor.post('message') >>> print(f.result())
-
class
wbia.web.futures_utils._base_actor.
ActorExecutor
[source]¶ Bases:
concurrent.futures._base.Executor
Executor to manage exactly one actor.
This class lives in the main thread, manages a process containing exactly one Actor, and is used to send messages to that actor. Responses are returned in the form of a Future object.
wbia.web.futures_utils.process_actor module¶
Implements ProcessActor
-
class
wbia.web.futures_utils.process_actor.
ProcessActorExecutor
(_ActorClass, *args, **kwargs)[source]¶ Bases:
wbia.web.futures_utils._base_actor.ActorExecutor
-
post
(message)[source]¶ analagous to _base.Executor.submit, but sends a message to the actor controlled by this Executor, and returns a Future.
-
shutdown
(wait=True)[source]¶ Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other methods can be called after this one.
Parameters: wait – If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed.
-
wbia.web.futures_utils.tests module¶
-
class
wbia.web.futures_utils.tests.
TestActorMixin
(a=None, factor=1)[source]¶ Bases:
object
An actor is given messages from its manager and performs actions in a single thread. Its state is private and threadsafe.
The handle method must be implemented by the user.
-
class
wbia.web.futures_utils.tests.
TestProcessActor
(a=None, factor=1)[source]¶ Bases:
wbia.web.futures_utils.tests.TestActorMixin
,wbia.web.futures_utils.process_actor.ProcessActor
-
class
wbia.web.futures_utils.tests.
TestThreadActor
(a=None, factor=1)[source]¶ Bases:
wbia.web.futures_utils.tests.TestActorMixin
,wbia.web.futures_utils.thread_actor.ThreadActor
wbia.web.futures_utils.thread_actor module¶
Implements ThreadActor
-
class
wbia.web.futures_utils.thread_actor.
ThreadActorExecutor
(_ActorClass, *args, **kwargs)[source]¶ Bases:
wbia.web.futures_utils._base_actor.ActorExecutor
-
post
(message)[source]¶ analagous to _base.Executor.submit, but sends a message to the actor controlled by this Executor, and returns a Future.
-
shutdown
(wait=True)[source]¶ Clean-up the resources associated with the Executor.
It is safe to call this method several times. Otherwise, no other methods can be called after this one.
Parameters: wait – If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed.
-