Package wtf :: Module util :: Class BasePool
[hide private]
[frames] | no frames]

Class BasePool

source code

object --+
         |
        BasePool
Known Subclasses:

Abstract pool of arbitrary objects
Instance Methods [hide private]
 
__init__(self, maxout, maxcached)
Initialization
source code
 
__del__(self)
Destruction
source code
PooledInterface
_create(self)
Create a pooled object
source code
PooledInterface
get_obj(self)
Get a object from the pool
source code
 
put_obj(self, obj)
Put an object back into the pool
source code
 
del_obj(self, obj)
Remove object from pool
source code
 
clear(self)
Clear the currently cached connections
source code
 
shutdown(self)
Shutdown this pool
source code
 
_fork_protect(self)
Check if the current PID differs from the stored one
source code

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

Class Variables [hide private]
NoneType _LOCK = None
Locking class.
bool _FORK_PROTECT = False
Clear the pool, when the PID changes?
Instance Variables [hide private]
int _maxcached
Maximum number of pooled objects to be cached
int _maxout
Hard maximum number of pooled objects to be handed out
threading.Condition _not_empty
"not empty" condition
threading.Condition _not_full
"not full" condition
dict _obj
References to handed out objects, Note that the objects need to be hashable
int _pid = None
PID of currently handed out and cached objects
collections.deque _pool
actual object pool
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, maxout, maxcached)
(Constructor)

source code 
Initialization
Overrides: object.__init__

_create(self)

source code 

Create a pooled object

This method must be implemented by subclasses.

Returns: PooledInterface
A new object

get_obj(self)

source code 
Get a object from the pool
Returns: PooledInterface
The new object. If no objects are available in the pool, a new one is created (by calling _create). If no object can be created (because of limits), the method blocks.

put_obj(self, obj)

source code 

Put an object back into the pool

If the pool is full, the object is destroyed instead. If the object does not come from this pool, it is an error (assert).

Parameters:

del_obj(self, obj)

source code 

Remove object from pool

If the object original came not from this pool, this is not an error.

Parameters:

clear(self)

source code 

Clear the currently cached connections

Connections handed out are not affected. This just empties the cached ones.

shutdown(self)

source code 

Shutdown this pool

The queue will be emptied and all objects destroyed. No more objects will be created in this pool. Waiting consumers of the pool will get an AssertionError, because they shouldn't consume anymore anyway.

_fork_protect(self)

source code 

Check if the current PID differs from the stored one

If they actually differed, we forked and clear the pool. This function should only be called within a locked environment.


Class Variable Details [hide private]

_LOCK

Locking class. By default this is threading.Lock. However, if the pooled object's initializer or destructor (.destroy) are calling back into get_conn or put_conn, it should be RLock.
Type:
NoneType
Value:
None