traits_futures.traits_executor module

Main-thread executor for submission of background tasks.

traits_futures.traits_executor.ExecutorState = Enum(RUNNING, STOPPING, STOPPED)

Trait type representing the executor state.

traits_futures.traits_executor.RUNNING = 'running'

Executor is currently running (this is the initial state).

traits_futures.traits_executor.STOPPED = 'stopped'

Executor is stopped.

traits_futures.traits_executor.STOPPING = 'stopping'

Executor has been requested to stop. In this state, no new jobs can be submitted, and we’re waiting for old ones to complete.

class traits_futures.traits_executor.TraitsExecutor(thread_pool=None, **traits)[source]

Bases: traits.has_traits.HasStrictTraits

Executor to initiate and manage background tasks.

running = Property(Bool())

Derived state: true if this executor is running; False if it’s stopped or stopping.

state = ExecutorState

Current state of this executor.

stop()[source]

Initiate stop: cancel existing jobs and prevent new ones.

stopped = Property(Bool())

Derived state: true if this executor is stopped and it’s safe to dispose of related resources (like the thread pool).

submit(task)[source]

Submit a task to the executor, and return the corresponding future.

Parameters:task (BackgroundCall, BackgroundIteration or BackgroundProgress) – The task to be executed.
Returns:future – Future for this task.
Return type:CallFuture, IterationFuture or ProgressFuture
submit_call(callable, *args, **kwargs)[source]

Convenience function to submit a background call.

Parameters:
  • callable (an arbitrary callable) – Function to execute in the background.
  • *args – Positional arguments to pass to that function.
  • **kwargs – Named arguments to pass to that function.
Returns:

future – Object representing the state of the background call.

Return type:

CallFuture

submit_iteration(callable, *args, **kwargs)[source]

Convenience function to submit a background iteration.

Parameters:
  • callable (an arbitrary callable) – Function executed in the background to provide the iterable.
  • *args – Positional arguments to pass to that function.
  • **kwargs – Named arguments to pass to that function.
Returns:

future – Object representing the state of the background iteration.

Return type:

IterationFuture

submit_progress(callable, *args, **kwargs)[source]

Convenience function to submit a background progress call.

Parameters:
  • callable (callable accepting a "progress" named argument) – Function executed in the background to provide the iterable. This should accept a “progress” named argument. The callable can then call the “progress” object to report progress.
  • *args – Positional arguments to pass to that function.
  • **kwargs – Named arguments to pass to that function. These should not include “progress”.
Returns:

future – Object representing the state of the background task.

Return type:

ProgressFuture

Previous topic

traits_futures.toolkit_support module

Next topic

traits_futures.version module

This Page