Powered by Tachyonic Project Luxon Framework v1.4.0

Luxon Framework for rapid application development. (luxon)


Pool Utility

Proxy Object

class luxon.utils.pool.ProxyObject(obj, pool)[source]

Class ProxyObject

Class that creates objects with same attributes as the original, but is also aware of object pool.

When the close() method is called on the Proxy object, it will not really be closed, and instead simply returned to the pool.

Unless the pool limit has been reached, in which case the real close() method will be called on the object.

  • obj (obj) – original (proxied) object.
  • pool (Pool) – queue.Queue object which is the pool.

Method close()

Put back in queue this proxy object. But only if we have not exceeded pool_size.

Pool Class

class luxon.utils.pool.Pool(get_obj_func, pool_size=10, max_overflow=10)[source]

Class Pool.

Pool manager for any objects such as db connections.

Specify pool_size and max_overflow when creating the pool object. Call it to obtain a connector object. If one is available in the pool, it will be returned, otherwise a new object will be created and returned.

  • get_obj_func (obj) – The function that creates and returns the connector object.
  • pool_size (int) – Length of the queue. At any given time no more than this many objects will exist in the queue.
  • max_overflow (int) – How many objects can be created over an above the pool size. The maximum number of objects that will exist at any given time equals the sum of pool_size and max_overflow. When the number of created objects exceed the pool_size, the next object to be closed will really be closed and not returned to the pool.


def someFunc():
    return some_connector_object

pool = Pool(someFunc, pool_size=10, max_overflow=10)

conn = pool()


with pool() as conn: