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.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 background_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 can be used either in the form send(message_type) or in the form send(message_type, message_args). Here message_type is a simple constant (typically a string), and message_args is a single Python object containing optional arguments for the message. The arguments to send 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 either True to indicate that cancellation has been requested, or False.

Note that there’s no obligation for the background task to check the cancellation status.

Returns

task

Return type

callable

abstract future()[source]

Return a Future for the background task.

Returns

future – Future object that can be used to monitor the status of the background task.

Return type

IFuture