If more than *min_size* connections are requested concurrently, new ones are
created, up to *max_size*. Note that the connections are always created by the
background workers, not by the thread asking the connection: if a client
-requires a new connection, and a previous client terminates its job before the
+requests a new connection, and a previous client terminates its job before the
new connection is ready, the waiting client will be served the existing
connection. This is especially useful in scenarios where the time to connect
is longer than the time the connection is used (see `this analysis`__, for
larger number of users to use them. See :ref:`connection-pools` for more
details and usage pattern.
-There package implement two connection pools: `ConnectionPool` is a
+This module implement two connection pools: `ConnectionPool` is a
synchronous connection pool yielding `~psycopg.Connection` objects and can be
used by multithread applications. `AsyncConnectionPool` has a similar
interface, but with `asyncio` functions replacing blocking functions, and
:type timeout: `!float`, default: 30 seconds
:param max_waiting: Maximum number of requests that can be queued to the
- pool. Requesting will fail, raising `TooManyRequests`.
- 0 means no queue limit.
+ pool, after which new requests will fail, raising
+ `TooManyRequests`. 0 means no queue limit.
:type max_waiting: `!int`, default: 0
:param max_lifetime: The maximum lifetime of a connection in the pool, in
.. automethod:: getconn
.. automethod:: putconn
+Pool exceptions
+---------------
.. autoclass:: PoolTimeout()
`!AsyncConnectionPool` has a very similar interface to the `ConnectionPool`
class but its blocking method are implemented as `async` coroutines. It
-returns `AsyncConnection` instances, or its subclasses if specified so in the
-*connection_class* parameter.
+returns `~psycopg.AsyncConnection` instances, or its subclasses if specified
+so in the *connection_class* parameter.
Only the function with different signature from `!ConnectionPool` are
listed here.
) -> Iterator[Connection[Any]]:
"""Context manager to obtain a connection from the pool.
- Returned the connection immediately if available, otherwise wait up to
+ Return the connection immediately if available, otherwise wait up to
*timeout* or `self.timeout` seconds and throw `PoolTimeout` if a
connection is not available in time.
with a `PoolClosed` exception. Currently used connections will not be
closed until returned to the pool.
- Wait *timeout* for threads to terminate their job, if positive. If
- timeout expires the pool is closed anyway, although it may raise some
- warnings on exit.
+ Wait *timeout* seconds for threads to terminate their job, if positive.
+ If the timeout expires the pool is closed anyway, although it may raise
+ some warnings on exit.
"""
if self._closed:
return