Connection Pool¶
- class nextorm.pool.ConnectionPool[source]¶
Bases:
objectThread-safe synchronous connection pool.
Parameters¶
- factory:
Zero-argument callable that creates and returns a new connection.
- min_size:
Number of connections to pre-create at construction time (0 is valid).
- max_size:
Maximum total number of connections. Once reached,
acquire()blocks until a connection is released or timeout expires.- timeout:
Seconds to wait for a free connection before raising
PoolTimeoutError.
- acquire()[source]¶
Check out a connection from the pool.
Returns immediately when an idle connection is available. Creates a new connection when the pool is below max_size. Blocks up to timeout seconds when the pool is at max_size.
Raises¶
- PoolTimeoutError
If no connection becomes available within the timeout.
- Return type:
- close_all()[source]¶
Close all idle connections in the pool.
Connections that are currently checked out are not affected; they will be closed when
release()is called and the pool detects that it is shutting down (currently the pool does not track checked-out connections, so callers must ensure all connections are released before calling this method if a clean shutdown is required).- Return type:
None
- class nextorm.pool.AsyncConnectionPool[source]¶
Bases:
objectAsync connection pool (uses
asynciosynchronisation primitives).Parameters¶
- factory:
Async callable that creates and returns a new async connection.
- min_size:
Number of connections to pre-create during
start().- max_size:
Maximum total number of connections.
- timeout:
Seconds to wait for a free connection before raising
PoolTimeoutError.
- async start()[source]¶
Pre-create min_size connections. Must be called inside an event loop.
- Return type:
None
- async acquire()[source]¶
Check out an async connection from the pool.
Raises¶
- PoolTimeoutError
If no connection becomes available within the timeout.
- Return type: