Module threadpool :: Class ThreadPool
[frames] | no frames]

Class ThreadPool

source code

A thread pool, distributing work requests and collecting results.

See the module docstring for more information.

Instance Methods
 
__init__(self, num_workers, q_size=0, resq_size=0, poll_timeout=5)
Set up the thread pool and start num_workers worker threads.
source code
 
createWorkers(self, num_workers, poll_timeout=5)
Add num_workers worker threads to the pool.
source code
 
dismissWorkers(self, num_workers, do_join=False)
Tell num_workers worker threads to quit after their current task.
source code
 
joinAllDismissedWorkers(self)
Perform Thread.join() on all worker threads that have been dismissed.
source code
 
putRequest(self, request, block=True, timeout=None)
Put work request into work queue and save its id for later.
source code
 
poll(self, block=False)
Process any new results in the queue.
source code
 
wait(self)
Wait for results, blocking until all have arrived.
source code
Method Details

__init__(self, num_workers, q_size=0, resq_size=0, poll_timeout=5)
(Constructor)

source code 

Set up the thread pool and start num_workers worker threads.

num_workers is the number of worker threads to start initially.

If q_size > 0 the size of the work request queue is limited and the thread pool blocks when the queue is full and it tries to put more work requests in it (see putRequest method), unless you also use a positive timeout value for putRequest.

If resq_size > 0 the size of the results queue is limited and the worker threads will block when the queue is full and they try to put new results in it.

createWorkers(self, num_workers, poll_timeout=5)

source code 

Add num_workers worker threads to the pool.

poll_timout sets the interval in seconds (int or float) for how ofte threads should check whether they are dismissed, while waiting for requests.