circuits.core.workers module¶
Workers
Worker is a component used to perform “work” in independent threads or processes. Simply create an instance of Worker() with either process=True to create a pool of workers using sub-processes for CPU-bound work or False (the default) for a thread pool of workers for I/O bound work.
Then fire task() events with a function and *args and **kwargs to pass to the function when called from within the workers.
- class circuits.core.workers.task(f, *args, **kwargs)¶
Bases:
Event
task Event
This Event is used to initiate a new task to be performed by a Worker
- Parameters
f (function) – The function to be executed.
args (tuple) – Arguments to pass to the function
kwargs (dict) – Keyword Arguments to pass to the function
x.__init__(…) initializes x; see x.__class__.__doc__ for signature
- success = True¶
- failure = True¶
- class circuits.core.workers.Worker(*args, **kwargs)¶
Bases:
BaseComponent
A thread/process Worker Component
This Component creates a pool of workers (either a thread or process) and executures the supplied function from a task() event passing supplied arguments and keyword-arguments to the function.
A task_success event is fired upon successful execution of the function and task_failure if it failed and threw an exception. The task() event can also be “waited” upon by using the .call() and .wait() primitives.
- Parameters
process (bool) – True to start this Worker as a process (Thread otherwise)
initializes x; see x.__class__.__doc__ for signature
- channel = 'worker'¶
- init(process=False, workers=None, channel='worker')¶