Why Requests Opens More Connections Than pool_maxsize
Use pool_block for a bounded pool, and add an application budget when the limit must cover all traffic through a proxy.
With the default pool_block=False, pool_maxsize limits retained connections in a pool, not every simultaneous connection. Requests can create extras and discard them afterward.
For a bounded pool used by an existing session's HTTPS requests:
from requests.adapters import HTTPAdapter
adapter = HTTPAdapter(
pool_connections=10,
pool_maxsize=4,
pool_block=True,
)
session.mount("https://", adapter)The mount selects HTTPS destination URLs. HTTP requests use the adapter mounted under http://.
| Input | What it controls |
|---|---|
| pool_connections | How many pools the manager caches |
| pool_maxsize | Connections within a pool |
| pool_block=True | Wait for a pool connection instead of creating an extra |
Requests also caches proxy managers by proxy URL. These values do not form one total cap across a rotating list of proxies and destinations. Use an application-level concurrency budget if the requirement is all work through one intermediary.
Blocking makes response release essential: consume bodies or close streaming responses so waiting work can proceed. Requests' adapter does not supply a separate timeout for this pool wait in the shown arrangement.