traits_futures.background_iteration module

Background task that sends results from an iteration.

class traits_futures.background_iteration.BackgroundIteration[source]

Bases: traits.has_traits.HasStrictTraits

Object representing the background iteration to be executed.

args = Tuple()

Positional arguments to be passed to the callable.

callable = Callable()

The callable to be executed. This should return something iterable.

future_and_callable(cancel_event, message_sender, message_receiver)[source]

Return a future and a linked background callable.

Parameters:
  • 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.
Returns:

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

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

Named arguments to be passed to the callable.

traits_futures.background_iteration.EXHAUSTED = 'exhausted'

Iteration completed normally. No arguments.

traits_futures.background_iteration.GENERATED = 'generated'

Message sent whenever the iteration yields a result. Argument is the result generated.

traits_futures.background_iteration.INTERRUPTED = 'interrupted'

Iteration was cancelled either before it started or during the iteration. No arguments.

class traits_futures.background_iteration.IterationBackgroundTask(callable, args, kwargs, message_sender, cancel_event)[source]

Bases: object

Iteration to be executed in the background.

send(message_type, message_args=None)[source]

Send a message to the linked IterationFuture.

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.

Parameters:
  • 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_iteration.IterationFuture[source]

Bases: traits.has_traits.HasStrictTraits

Foreground representation of an iteration executing in the background.

cancel()[source]

Method called from the main thread to request cancellation of the background job.

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 iteration, else False. True indicates either that the background iteration succeeded, or that it raised, or that it was cancelled.

exception = CANCELLING
result_event = Event(Any())

Event fired whenever a result arrives from the background iteration.

state = FutureState

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

traits_futures.background_iteration.RAISED = 'raised'

Iteration failed with an exception, or there was an exception on creation of the iterator. Argument gives exception information.

traits_futures.background_iteration.STARTED = 'started'

Iteration started executing. No arguments.

Previous topic

traits_futures.background_call module

Next topic

traits_futures.background_progress module

This Page