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
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
state
is one ofWAITING
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
.
-
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 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.
-
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 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
= 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
.
-
abstract