traits_futures.traits_executor module¶
Executor to submit 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, *, worker_pool=None, max_workers=None, context=None, **traits)[source]¶ Bases:
traits.has_traits.HasStrictTraits
Executor to initiate and manage background tasks.
- Parameters
thread_pool (concurrent.futures.Executor, optional) –
Deprecated alias for worker_pool.
Deprecated since version 0.2: Use
worker_pool
instead.worker_pool (concurrent.futures.Executor, optional) – If supplied, provides the underlying worker pool executor to use. In this case, the creator of the TraitsExecutor is responsible for shutting down the worker pool once it’s no longer needed. If not supplied, a new private worker pool will be created, and this object’s
stop
method will shut down that worker pool.max_workers (int or None, optional) – Maximum number of workers for the private worker pool. This parameter is mutually exclusive with
worker_pool
. The default isNone
, which delegates the choice of number of workers to Python’sconcurrent.futures
module.context (IParallelContext, optional) – Parallelism context, providing appropriate concurrent primitives and worker pools for a given choice of parallelism (for example multithreading or multiprocessing). If not given, assumes multithreading. Note that if both
context
andworker_pool
are given, they must be compatible.
-
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.
-
stopped
= Property(Bool())¶ Derived state: true if this executor is stopped and it’s safe to dispose of related resources (like the worker pool).
-
submit
(task)[source]¶ Submit a task to the executor, and return the corresponding future.
- Parameters
task (ITaskSpecification) –
- Returns
future – Future for this task.
- Return type
-
submit_call
(callable, *args, **kwargs)[source]¶ Convenience function to submit a background call.
Deprecated since version 0.2: Use the
submit_call
function instead.- 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
-
submit_iteration
(callable, *args, **kwargs)[source]¶ Convenience function to submit a background iteration.
Deprecated since version 0.2: Use the
submit_iteration
function instead.- 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
-
submit_progress
(callable, *args, **kwargs)[source]¶ Convenience function to submit a background progress call.
Deprecated since version 0.2: Use the
submit_progress
function instead.- 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