traits_futures.base_future module

Base class providing common pieces of the Future machinery.

class traits_futures.base_future.BaseFuture[source]

Bases: traits.has_traits.HasStrictTraits

Convenience base class for the various flavours of Future.

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 future’s state is either 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.

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.

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 = Property(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.