traits_futures.background_call module

Background task consisting of a simple callable.

class traits_futures.background_call.BackgroundCall[source]

Bases: traits.has_traits.HasStrictTraits

Object representing the background call to be executed.

args = Tuple()

Positional arguments to be passed to the callable.

callable = Callable()

The callable to be executed.

future_and_callable(cancel_event, message_sender, message_receiver)[source]

Return a future and a linked background callable.

  • cancel_event (threading.Event) – Event used to request cancellation of the background job.
  • message_sender (MessageSender) – Object used by the background job to send messages to the UI. Supports the context manager protocol, and provides a ‘send’ method.
  • message_receiver (MessageReceiver) – Object that remains in the main thread and receives messages sent by the message sender. This is a HasTraits subclass with a ‘message’ Event trait that can be listened to for arriving messages.

  • future (CallFuture) – Foreground object representing the state of the running calculation.
  • runner (CallBackgroundTask) – Callable to be executed in the background.

kwargs = Dict(Str(), Any())

Named arguments to be passed to the callable.

class traits_futures.background_call.CallBackgroundTask(callable, args, kwargs, message_sender, cancel_event)[source]

Bases: object

Wrapper around the actual callable to be run. This wrapper provides the task that will be submitted to the concurrent.futures executor

send(message_type, message_args=None)[source]

Send a message to the linked CallFuture.

Sends a pair consisting of a string giving the message type along with an object providing any relevant arguments. The interpretation of the arguments depends on the message type.

  • message_type (string) – Type of the message to be sent.
  • message_args (object, optional) – Any arguments relevant to the message. Ideally, should be pickleable and immutable. If not provided, None is sent.
class traits_futures.background_call.CallFuture[source]

Bases: traits.has_traits.HasStrictTraits

Object representing the front-end handle to a background call.


Method that can be called from the main thread to indicate that the task should be cancelled (provided it hasn’t already started running).

cancellable = Property(Bool())

True if this task can be cancelled, else False.

done = Property(Bool())

True if we’ve received the final message from the background task, else False. True indicates either that the background task succeeded, or that it raised, or that it was cancelled.

exception = CANCELLING
state = FutureState

The state of the background call, to the best of the knowledge of this future.

traits_futures.background_call.INTERRUPTED = 'interrupted'

Call was cancelled before it started. No arguments.

traits_futures.background_call.RAISED = 'raised'

Call failed with an exception. Argument gives exception information.

traits_futures.background_call.RETURNED = 'returned'

Call succeeded and returned a result. Argument is the result.

traits_futures.background_call.STARTED = 'started'

Call started executing. No arguments.

Previous topic

traits_futures.api module

Next topic

traits_futures.background_iteration module

This Page