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
orEXECUTING
state will immediately be moved toCANCELLING
state. If the task is not inWAITING
orEXECUTING
state, this function will raiseRuntimeError
.- 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 eitherWAITING
orEXECUTING
.
-
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 ofCOMPLETED
,FAILED
, orCANCELLED
. 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 thestate
.
-
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 theFAILED
state, any attempt to access this attribute will raise anAttributeError.
- Returns
exc_info – Tuple containing exception information in string form: (exception type, exception value, formatted traceback).
- Return type
- 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 theCOMPLETED
state, any attempt to access this attribute will raise anAttributeError
.- Returns
result – The result obtained from the background task.
- Return type
- 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
orCANCELLED
.
-