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.
Put back in queue this proxy object. But only if we have not exceeded pool_size.
Pool(get_obj_func, pool_size=10, max_overflow=10)¶
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.
def someFunc(): return some_connector_object pool = Pool(someFunc, pool_size=10, max_overflow=10) conn = pool() conn.someMethod() conn.close()
with pool() as conn: conn.someMethod()