Package ganeti :: Module workerpool :: Class WorkerPool
[hide private]
[frames] | no frames]

Class WorkerPool

source code


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.

Instance Methods [hide private]
 
__init__(self, name, num_workers, worker_class)
Constructor for worker pool.
source code
 
_WaitWhileQuiescingUnlocked(self)
Wait until the worker pool has finished quiescing.
source code
 
_AddTaskUnlocked(self, args) source code
 
AddTask(self, args)
Adds a task to the queue.
source code
 
AddManyTasks(self, tasks)
Add a list of tasks to the queue.
source code
 
_WaitForTaskUnlocked(self, worker)
Waits for a task for a worker.
source code
 
_ShouldWorkerTerminateUnlocked(self, worker)
Returns whether a worker should terminate.
source code
 
_HasRunningTasksUnlocked(self)
Checks whether there's a task running in a worker.
source code
 
Quiesce(self)
Waits until the task queue is empty.
source code
 
_NewWorkerIdUnlocked(self)
Return an identifier for a new worker.
source code
 
_ResizeUnlocked(self, num_workers)
Changes the number of workers.
source code
 
Resize(self, num_workers)
Changes the number of workers in the pool.
source code
 
TerminateWorkers(self)
Terminate all worker threads.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, num_workers, worker_class)
(Constructor)

source code 

Constructor for worker pool.

Parameters:
  • num_workers - number of workers to be started (dynamic resizing is not yet implemented)
  • worker_class - the class to be instantiated for workers; should derive from BaseWorker
Overrides: object.__init__

AddTask(self, args)

source code 

Adds a task to the queue.

Parameters:

AddManyTasks(self, tasks)

source code 

Add a list of tasks to the queue.

Parameters:

_WaitForTaskUnlocked(self, worker)

source code 

Waits for a task for a worker.

Parameters:

Resize(self, num_workers)

source code 

Changes the number of workers in the pool.

Parameters:
  • num_workers - the new number of workers

TerminateWorkers(self)

source code 

Terminate all worker threads.

Unstarted tasks will be ignored.