Package gofer :: Package rmi :: Module threadpool :: Class ThreadPool
[hide private]
[frames] | no frames]

Class ThreadPool

source code

A load distributed thread pool.

Instance Methods [hide private]
 
__init__(self, min=1, max=1, duplex=True) source code
 
run(self, fn, *args, **kwargs)
Schedule a call.
source code
str
schedule(self, call)
Schedule a call.
source code
tuple(2)
get(self, blocking=True, timeout=None)
Get the results of calls executed in the pool.
source code
object
find(self, id=None, blocking=True, timeout=None)
Find the results of calls executed in the pool by job ID.
source code
 
pending(self)
Used by worker to get the next pending call.
source code
 
completed(self, call)
Result received.
source code
dict
info(self)
Get pool statistics.
source code
 
shutdown(self)
Shutdown the pool.
source code
 
__track(*args, **kwargs)
Call has been scheduled.
source code
 
__add(*args, **kwargs)
Add a thread to the pool.
source code
 
__expand(*args, **kwargs)
Expand the worker pool based on needed capacity.
source code
 
__lock(self) source code
 
__unlock(self) source code
 
__len__(*args, **kwargs) source code
 
__repr__(self) source code
Instance Variables [hide private]
RLock __mutex
The pool mutex.
Queue __pending
The worker pending queue.
list __threads
The list of workers
tuple(2) __tracking
The job tracking dict(s) (<pending>,<completed>)
int max
The max # of workers.
int min
The min # of workers.
Method Details [hide private]

__init__(self, min=1, max=1, duplex=True)
(Constructor)

source code 
Parameters:
  • min (int) - The min # of workers.
  • max (int) - The max # of workers.
  • duplex (bool) - Indicates that the pool supports bidirectional communication. That is, call results are queued. (default: True).

run(self, fn, *args, **kwargs)

source code 

Schedule a call. Convenience method for scheduling.

Parameters:
  • fn (callable) - A function/method to execute.
  • args (tuple) - The args passed to fn()
  • kwargs (dict @return The call ID. @rtype str) - The keyword args passed fn()

schedule(self, call)

source code 

Schedule a call.

Parameters:
  • call - A call to schedule for execution.
  • call - Call
Returns: str
The call ID.

get(self, blocking=True, timeout=None)

source code 

Get the results of calls executed in the pool.

Parameters:
  • id (str) - A job ID.
  • blocking (bool) - Block when queue is empty.
  • timeout - The time (seconds) to block when empty.
Returns: tuple(2)
Call result (call, retval)

find(self, id=None, blocking=True, timeout=None)

source code 

Find the results of calls executed in the pool by job ID.

Parameters:
  • id (str) - A job ID.
  • blocking (bool) - Block when queue is empty.
  • timeout - The time (seconds) to block when empty.
Returns: object
Call return value

pending(self)

source code 

Used by worker to get the next pending call.

Returns:
The next pending call. @rtype Call

completed(self, call)

source code 

Result received.

Parameters:
  • call (Call) - A call object.

info(self)

source code 

Get pool statistics.

Returns: dict
pool statistics
  • capacity: number of allocated threads
  • running: number of calls currently queued.
  • completed: number of calls completed but return has not been consumed using get() or find().

shutdown(self)

source code 

Shutdown the pool. Terminate and join all workers.

__track(*args, **kwargs)

source code 

Call has been scheduled.

Parameters:
  • call (tuple(4)) - A call (id, fn, args, kwargs).
Decorators:
  • @synchronized

__add(*args, **kwargs)

source code 

Add a thread to the pool.

Decorators:
  • @synchronized

__expand(*args, **kwargs)

source code 

Expand the worker pool based on needed capacity.

Decorators:
  • @synchronized

__len__(*args, **kwargs)
(Length operator)

source code 
Decorators:
  • @synchronized