Package pysys :: Package utils :: Module threadpool :: Class ThreadPool
[hide private]
[frames] | no frames]

Class ThreadPool

source code

Main pool to manage worker threads processing an internal request queue.

Instance Methods [hide private]
 
__init__(self, num_workers, q_size=0, resq_size=0, poll_timeout=5)
Class constructor.
source code
 
createWorkers(self, num_workers, poll_timeout=5)
Create additional threads on the workers stack.
source code
 
dismissWorkers(self, num_workers, do_join=False)
Dismiss worker threads from the workers stack.
source code
 
joinAllDismissedWorkers(self)
Join all dismissed workers.
source code
 
putRequest(self, request, block=True, timeout=0)
Place a WorkRequest on the request queue.
source code
 
poll(self, block=False)
Poll the request queue until the queue is empty.
source code
 
wait(self)
Block until there are no request results pending on the queue.
source code
Method Details [hide private]

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

source code 

Class constructor.

Parameters:
  • num_workers - The number of worker threads processing the queue
  • q_size - The request queue size
  • resq_size - The response queue size
  • poll_timeout - The polling timeout of worker threads when getting requests from the queue

createWorkers(self, num_workers, poll_timeout=5)

source code 

Create additional threads on the workers stack.

Parameters:
  • num_workers - The number of workers to add to the stack
  • poll_timeout - The timeout of the threads when waiting for a request on the queue

dismissWorkers(self, num_workers, do_join=False)

source code 

Dismiss worker threads from the workers stack.

Stops a set number of workers in the workers list by popping the workers of the list stack.

Parameters:
  • num_workers - The number of workers to dismiss
  • do_join - If True wait for all threads to terminate before returning from the call

joinAllDismissedWorkers(self)

source code 

Join all dismissed workers.

Blocks until all dismissed worker threads terminate. Use when calling dismissWorkers with do_join = False.

putRequest(self, request, block=True, timeout=0)

source code 

Place a WorkRequest on the request queue.

Parameters:
  • request - The WorkRequest to place on the request queue
  • block - If set to True, block queue operations until complete, otherwise use timeout
  • timeout - The timeout to use for queue operations when block is set to False

poll(self, block=False)

source code 

Poll the request queue until the queue is empty.

Raises a NoResultsPending or NoWorkersAvailable exception if the results queue is initially empty, or there are no available workers. Otherwise processes the results queue and calls the request callback with the result of the request.