class cuttlepool.CuttlePool(factory, capacity, overflow=0, timeout=None, resource_wrapper=None, **kwargs)[source]

A resource pool.

  • factory (func) – A factory that produces the desired resource.
  • capacity (int) – Max number of resource instances in the pool.
  • overflow (int) – The number of extra resource instances that can be made if the pool is exhausted. Defaults to 0.
  • timeout (int) – Time in seconds to wait for a resource. Defaults to None.
  • resource_wrapper – A Resource subclass.
  • **kwargs – Keyword arguments that are passed to factory when a resource instance is created.
  • ValueError – If capacity <= 0 or overflow < 0 or timeout < 0.
  • TypeError – If timeout is not int or None.

The maximum capacity the pool will hold under normal circumstances.


For compatibility with older versions, will be removed in 1.0.


Return True if pool is empty.


Return a copy of the factory arguments used to create a resource.


For compatibility with older versions, will be removed in 1.0.


Returns a Resource instance.

Parameters:resource_wrapper – A Resource subclass.
Returns:A Resource instance.
Raises:PoolEmptyError – If attempt to get resource fails or times out.

The maximum possible number of resource instances that can exist at any one time.


For compatibility with older versions, will be removed in 1.0.


A user implemented function that resets the properties of the resource instance that was created by factory. This prevents unwanted behavior from a resource retrieved from the pool as it could have been changed when previously used.

Parameters:resource (obj) – A resource instance.

The number of additional resource instances the pool will create when it is at capacity.


A user implemented function that ensures the Resource object is open.

Parameters:resource (obj) – A Resource object.
Returns:A bool indicating if the resource is open (True) or closed (False).

For compatibility with older versions, will be removed in 1.0.


Adds a resource back to the pool or discards it if the pool is full.

Parameters:resource – A resource object.
Raises:UnknownResourceError – If resource was not made by the pool.

The number of existing resource instances that have been made by the pool.

Note:This is not the number of resources in the pool, but the number of existing resources. This includes resources in the pool and resources in use.


This is not threadsafe. size can change when context switches to another thread.


The duration to wait for a resource to be returned to the pool when the pool is depleted.

class cuttlepool.Resource(resource, pool)[source]

A wrapper around a resource instance.

  • resource – A resource instance.
  • pool – A resource pool.

Returns the resource to the resource pool.

exception cuttlepool.CuttlePoolError[source]

Base class for exceptions in this module.

exception cuttlepool.PoolEmptyError[source]

Exception raised when pool timeouts.

exception cuttlepool.PoolFullError[source]

Exception raised when there is no space to add a resource.

exception cuttlepool.UnknownResourceError[source]

Exception raised when a resource is returned to the pool that was not made by the pool.