traits_futures.wrappers module

Wrappers for the background task callable and the foreground future.

These are used by the TraitsExecutor machinery.

class traits_futures.wrappers.BackgroundTaskWrapper(background_task, sender, cancel_event)[source]

Bases: object

Wrapper for callables submitted to the underlying executor.

Parameters
  • background_task (collections.abc.Callable) – Callable representing the background task. This will be called with arguments send and cancelled.

  • sender (MessageSender) – Object used to send messages.

  • cancelled (collections.abc.Callable) – Zero-argument callable returning bool. This can be called to check whether cancellation has been requested.

send_control_message(message_type, message_args=None)[source]

Send a control message from the background task to the future.

These messages apply to all futures, and are used to communicate changes to the state of the future.

send_custom_message(message_type, message_args=None)[source]

Send a custom message from the background task to the future.

Parameters
  • message_type (str) – The message type.

  • message_args (object, optional) – Any arguments providing additional information for the message. If not given, None is passed.

traits_futures.wrappers.CONTROL = 'control'

Prefix used for control messages.

traits_futures.wrappers.CUSTOM = 'custom'

Prefix used for custom messages.

class traits_futures.wrappers.FutureWrapper[source]

Bases: traits.has_traits.HasStrictTraits

Wrapper for the IFuture.

This wrapper handles control messages from the background task, and delegates custom messages to the future.

future = Instance(IFuture)

Future being wrapped

receiver = Instance(HasTraits)

Object that receives messages from the background task.

traits_futures.wrappers.RAISED = 'raised'

Control message sent when an exception was raised by the background callable. The argument is a tuple containing exception information.

traits_futures.wrappers.RETURNED = 'returned'

Control message sent to indicate that the background callable succeeded and returned a result. The argument is that result.

traits_futures.wrappers.STARTED = 'started'

Control message sent before we start to process the target callable. The argument is always None.