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¶
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()¶
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 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 receive(message)¶
Receive and process a message from the task associated to this future.
This method is primarily for use by the executors, but may also be of use in testing.
- class traits_futures.i_task_specification.ITaskSpecification¶
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)¶
Return a Future for the background task.
cancel – Zero-argument callable, returning no useful result. The returned future’s
cancelmethod should call this to request cancellation of the associated background task.
future – Future object that can be used to monitor the status of the background task.
- Return type
- abstract task()¶
Return the callable that will be invoked as the background task.
This callable should be pickleable and should have the signature
Any exception raised while executing the callable, or result returned by the callable, will be recorded in the corresponding future.
sendargument 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 as
messageis an arbitrary Python object. The argument to
sendshould typically be both immutable and pickleable.
sendreturns no useful result.
cancelledargument may be used by the background task to check whether cancellation has been requested. When called with no arguments, it returns either
Trueto indicate that cancellation has been requested, or
Note that there’s no obligation for the background task to check the cancellation status.
task – Callable accepting arguments
cancelled. The callable can use
sendto send messages and
cancelledto check whether cancellation has been requested.
- Return type