traits_futures.i_task_specification module¶
Interface for a job specification. The job specification is the object that the TraitsExecutor knows how to deal with.
-
class
traits_futures.i_task_specification.
IFuture
[source]¶ Bases:
abc.ABC
Interface for futures returned by the executor.
This interface can be used to implement new background task types. It represents the knowledge that the executor needs to interact with futures.
-
abstract
cancel
()[source]¶ Request cancellation of the background task.
For a future that has not yet completed and has not previously been cancelled, this method requests cancellation of the associated background task and returns
True
. For a future that has already completed, or that has previously been cancelled, this method does nothing, and returnsFalse
.- Returns
cancelled – True if the task was cancellable and this call requested cancellation, False if the task was not cancellable (in which case this call did nothing).
- Return type
-
abstract
-
class
traits_futures.i_task_specification.
ITaskSpecification
[source]¶ Bases:
abc.ABC
Specify background task callable and foreground future for a task.
An object implementing the ITaskSpecification interface describes how to create a background task and a corresponding foreground future to execute a particular type of background task. It’s consumed by the TraitsExecutor when submitting background tasks, and implemented by BackgroundCall, BackgroundIteration and others.
-
abstract
future
(cancel)[source]¶ Return a Future for the background task.
- Parameters
cancel – Zero-argument callable, returning no useful result. The returned future’s
cancel
method should call this to request cancellation of the associated background task.- Returns
future – Future object that can be used to monitor the status of the background task.
- Return type
-
abstract
task
()[source]¶ Return the callable that will be invoked as the background task.
This callable should be pickleable and should have the signature
task(send, cancelled)
Any exception raised while executing the callable, or result returned by the callable, will be recorded in the corresponding future.
The
send
argument can be used by the background task to send messages back to the main thread of execution. It’s a callable that should be called assend(message)
, wheremessage
is an arbitrary Python object. The argument tosend
should typically be both immutable and pickleable.send
returns no useful result.The
cancelled
argument may be used by the background task to check whether cancellation has been requested. When called with no arguments, it returns eitherTrue
to indicate that cancellation has been requested, orFalse
.Note that there’s no obligation for the background task to check the cancellation status.
- Returns
task – Callable accepting arguments
send
andcancelled
. The callable can usesend
to send messages andcancelled
to check whether cancellation has been requested.- Return type
-
abstract