traits_futures.multithreading_context module

Context providing multithreading-friendly worker pools, events, and routers.

class traits_futures.multithreading_context.MultithreadingContext[source]

Bases: IParallelContext

Context for multithreading, suitable for use with the TraitsExecutor.

close()[source]

Do any cleanup necessary before disposal of the context.

property closed

True if this context is closed, else False.

event()[source]

Return a shareable event suitable for this context.

Returns

event – An event that can be shared safely with workers. The event should have the same API as threading.Event and multiprocessing.Event, providing at a minimum the set and is_set methods from that API.

Return type

object

message_router(event_loop)[source]

Return a message router suitable for use in this context.

Parameters

event_loop (IEventLoop) – The event loop used to trigger message dispatch.

Returns

message_router

Return type

MultithreadingRouter

worker_pool(*, max_workers=None)[source]

Provide a new worker pool suitable for this context.

Parameters

max_workers (int, optional) – Maximum number of workers to use. If not given, the choice is delegated to the ThreadPoolExecutor.

Returns

executor

Return type

concurrent.futures.Executor