class WorkerPool(object):
Worker pool with a queue.
This class is thread-safe.
Tasks are guaranteed to be started in the order in which they're added to the pool. Due to the nature of threading, they're not guaranteed to finish in the same order.
Method | __init__ |
Constructor for worker pool. |
Method |
|
Add a list of tasks to the queue. |
Method |
|
Adds a task to the queue. |
Method |
|
Changes a task's priority. |
Method |
|
Checks whether there's at least one task running. |
Method |
|
Waits until the task queue is empty. |
Method |
|
Changes the number of workers in the pool. |
Method |
|
Terminate all worker threads. |
Method | _ |
Adds a task to the internal queue. |
Method | _ |
Checks whether there's a task running in a worker. |
Method | _ |
Return an identifier for a new worker. |
Method | _ |
Changes the number of workers. |
Method | _ |
Returns whether a worker should terminate. |
Method | _ |
Waits for a task for a worker. |
Method | _ |
Wait until the worker pool has finished quiescing. |
Instance Variable | _counter |
Undocumented |
Instance Variable | _last |
Undocumented |
Instance Variable | _lock |
Undocumented |
Instance Variable | _name |
Undocumented |
Instance Variable | _pool |
Undocumented |
Instance Variable | _pool |
Undocumented |
Instance Variable | _quiescing |
Undocumented |
Instance Variable | _taskdata |
Mapping from task IDs to entries in _tasks |
Instance Variable | _tasks |
Each tuple has the format (priority, order ID, task ID, arguments). Priority and order ID are numeric and essentially control the sort order. The order ID is an increasing number denoting the order in which tasks are added to the queue... |
Instance Variable | _termworkers |
Undocumented |
Instance Variable | _worker |
Undocumented |
Instance Variable | _worker |
Undocumented |
Instance Variable | _workers |
Undocumented |
Constructor for worker pool.
Parameters | |
name | Undocumented |
num | number of workers to be started (dynamic resizing is not yet implemented) |
worker | the class to be instantiated for workers; should derive from BaseWorker |
Add a list of tasks to the queue.
Parameters | |
tasks:list of tuples | list of args passed to BaseWorker.RunTask |
priority:number or list of numbers | Priority for all added tasks or a list with the priority for each task |
task | List with the ID for each task |
Note | |
See AddTask for a note on task IDs. |
Adds a task to the queue.
Parameters | |
args:sequence | arguments passed to BaseWorker.RunTask |
priority:number | Task priority |
task | Task ID |
Note | |
The task ID can be essentially anything that can be used as a dictionary key. Callers, however, must ensure a task ID is unique while a task is in the pool or while it might return to the pool due to deferring using DeferTask . |
Changes a task's priority.
Parameters | |
task | Task ID |
priority:number | New task priority |
Raises | |
NoSuchTask | When the task referred by task_id can not be found (it may never have existed, may have already been processed, or is currently running) |
Adds a task to the internal queue.
Parameters | |
args:sequence | Arguments passed to BaseWorker.RunTask |
priority:number | Task priority |
task | Task ID |
Mapping from task IDs to entries in _tasks
Each tuple has the format (priority, order ID, task ID, arguments). Priority and order ID are numeric and essentially control the sort order. The order ID is an increasing number denoting the order in which tasks are added to the queue. The task ID is controlled by user of workerpool, see AddTask
for details. The task arguments are None for abandoned tasks, otherwise a sequence of arguments to be passed to BaseWorker.RunTask
). The list must fulfill the heap property (for use by the heapq module).