+# WARNING: this file is auto-generated by 'async_to_sync.py'
+# from the original file 'null_pool_async.py'
+# DO NOT CHANGE! Change the original file instead.
"""
Psycopg null connection pool module.
"""
from psycopg.rows import TupleRow
from .abc import CT, ConnectionCB, ConnectFailedCB
-from .pool import ConnectionPool, AddConnection
from .errors import PoolTimeout, TooManyRequests
from ._compat import ConnectionTimeout
from ._acompat import Event
from .base_null_pool import _BaseNullConnectionPool
+from .pool import ConnectionPool, AddConnection
logger = logging.getLogger("psycopg.pool")
configure: Optional[ConnectionCB[CT]] = None,
reset: Optional[ConnectionCB[CT]] = None,
kwargs: Optional[Dict[str, Any]] = None,
- # Note: default value changed to 0.
min_size: int = 0,
max_size: Optional[int] = None,
name: Optional[str] = None,
reconnect_timeout: float = 5 * 60.0,
reconnect_failed: Optional[ConnectFailedCB] = None,
num_workers: int = 3,
- ):
+ ): # Note: min_size default value changed to 0.
super().__init__(
conninfo,
open=open,
logger.info("waiting for pool %r initialization", self.name)
self.run_task(AddConnection(self))
if not self._pool_full_event.wait(timeout):
- self.close() # stop all the threads
+ self.close() # stop all the tasks
raise PoolTimeout(f"pool initialization incomplete after {timeout} sec")
with self._lock:
except ConnectionTimeout as ex:
raise PoolTimeout(str(ex)) from None
self._nconns += 1
-
elif self.max_waiting and len(self._waiting) >= self.max_waiting:
self._stats[self._REQUESTS_ERRORS] += 1
raise TooManyRequests(
f"the pool {self.name!r} has already"
- f" {len(self._waiting)} requests waiting"
+ + f" {len(self._waiting)} requests waiting"
)
return conn
def _maybe_close_connection(self, conn: CT) -> bool:
+ # Close the connection if no client is waiting for it, or if the pool
+ # is closed. For extra refcare remove the pool reference from it.
+ # Maintain the stats.
with self._lock:
if not self._closed and self._waiting:
return False
Only *max_size* can be changed; *min_size* must remain 0.
"""
- min_size, max_size = self._check_size(min_size, max_size)
+ (min_size, max_size) = self._check_size(min_size, max_size)
logger.info(
"resizing %r to min_size=%s max_size=%s", self.name, min_size, max_size
else:
# No client waiting for a connection: close the connection
conn.close()
-
# If we have been asked to wait for pool init, notify the
# waiter if the pool is ready.
if self._pool_full_event:
configure: Optional[AsyncConnectionCB[ACT]] = None,
reset: Optional[AsyncConnectionCB[ACT]] = None,
kwargs: Optional[Dict[str, Any]] = None,
- # Note: default value changed to 0.
- min_size: int = 0,
+ min_size: int = 0, # Note: min_size default value changed to 0.
max_size: Optional[int] = None,
name: Optional[str] = None,
timeout: float = 30.0,
self._stats[self._REQUESTS_ERRORS] += 1
raise TooManyRequests(
f"the pool {self.name!r} has already"
- f" {len(self._waiting)} requests waiting"
+ + f" {len(self._waiting)} requests waiting"
)
return conn