traits_futures.i_future module

Interface for futures returned by the executor.

class traits_futures.i_future.IFuture[source]

Bases: traits.has_traits.Interface

Interface for futures returned by the executor.

abstract cancel()[source]

Request cancellation of the background task.

A task in WAITING or EXECUTING state will immediately be moved to CANCELLING state. If the task is not in WAITING or EXECUTING state, this function will raise RuntimeError.

Raises

RuntimeError – If the task has already completed or cancellation has already been requested.

cancellable = Property(Bool())

True if cancellation of the background task can be requested, else False. Cancellation of the background task can be requested only if the state is one of WAITING or EXECUTING.

done = Property(Bool())

True when communications from the background task are complete. At that point, no further state changes can occur for this future. This trait has value True if the state is one of COMPLETED, FAILED, or CANCELLED. It’s safe to listen to this trait for changes: it will always fire exactly once, and when it fires it will be consistent with the state.

abstract property exception

Information about any exception raised by the background task.

This attribute is only available if the state of this future is FAILED. If the future has not reached the FAILED state, any attempt to access this attribute will raise an AttributeError.

Returns

exc_info – Tuple containing exception information in string form: (exception type, exception value, formatted traceback).

Return type

tuple(str, str, str)

Raises

AttributeError – If the task is still executing, or was cancelled, or completed without raising an exception.

message = Event(Tuple(Str(), Any()))

Event trait providing custom messages from the background task. Subclasses of BaseFuture can listen to this trait and interpret the messages in whatever way they like. Each message takes the form (message_type, message_args).

abstract property result

Result of the background task.

This attribute is only available if the state of the future is COMPLETED. If the future has not reached the COMPLETED state, any attempt to access this attribute will raise an AttributeError.

Returns

result – The result obtained from the background task.

Return type

object

Raises

AttributeError – If the task is still executing, or was cancelled, or raised an exception instead of returning a result.

state = FutureState

The state of the background task, to the best of the knowledge of this future. One of the six constants WAITING, EXECUTING, COMPLETED, FAILED, CANCELLING or CANCELLED.