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())
classmethod executor()[source]

Creates an asychronous instance of this Actor and returns the executor to manage it.

handle(message)[source]

This method recieves, handles, and responds to the messages sent from the executor. This function can return arbitrary values. These values can be accessed from the main thread using the Future object returned when the message was posted to this actor by the executor.

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.

post(message)[source]

analagous to _base.Executor.submit, but sends a message to the actor controlled by this Executor, and returns a Future.

wbia.web.futures_utils.process_actor module

Implements ProcessActor

class wbia.web.futures_utils.process_actor.ProcessActor[source]

Bases: wbia.web.futures_utils._base_actor.Actor

classmethod executor(*args, **kwargs)[source]

Creates an asychronous instance of this Actor and returns the executor to manage it.

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.

handle(message)[source]
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.tests.main()[source]

from wbia.web.futures_utils.tests import * ActorClass = TestProcessActor ActorClass = TestThreadActor

wbia.web.futures_utils.tests.test_actor_args(ActorClass)[source]
wbia.web.futures_utils.tests.test_callbacks(ActorClass)[source]
wbia.web.futures_utils.tests.test_cancel(ActorClass)[source]
wbia.web.futures_utils.tests.test_multiple(ActorClass)[source]
wbia.web.futures_utils.tests.test_simple(ActorClass)[source]

wbia.web.futures_utils.thread_actor module

Implements ThreadActor

class wbia.web.futures_utils.thread_actor.ThreadActor[source]

Bases: wbia.web.futures_utils._base_actor.Actor

classmethod executor(*args, **kwargs)[source]

Creates an asychronous instance of this Actor and returns the executor to manage it.

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.

Module contents