Skip to content
Myr

Adding an argument to the adapter for passing a block argument to the connection pool.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This allows for blocking when using threading to prevent the pool from creating more connections that the max-size allows. Specifically was seeing the following errors without the block=True: WARNING:requests.packages.urllib3.connectionpool:HttpConnectionPool is full, discarding connection: www.example.com

authored by Randy Merrill · committed by Randy Merrill · parent e7786ec · Browse files · 1 file+10 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+10 added−4 removed

  • other:+10 added−4 removed

1 file+10 added−4 removed

modified:requests/adapters.py+10 added-4 removed
23 unmodified lines
24from .cookies import extract_cookies_to_jar25from .exceptions import ConnectionError, Timeout, SSLError26from .auth import _basic_auth_str2728DEFAULT_POOLBLOCK = False29DEFAULT_POOLSIZE = 1030DEFAULT_RETRIES = 03132
31 unmodified lines
64 """65 __attrs__ = ['max_retries', 'config', '_pool_connections', '_pool_maxsize']6667 def __init__(self, pool_connections=DEFAULT_POOLSIZE,67 pool_maxsize=DEFAULT_POOLSIZE, max_retries=DEFAULT_RETRIES):68 pool_maxsize=DEFAULT_POOLSIZE, pool_block=DEFAULT_POOLBLOCK,69 max_retries=DEFAULT_RETRIES):70 self.max_retries = max_retries71 self.config = {}7273 super(HTTPAdapter, self).__init__()7475 self._pool_connections = pool_connections76 self._pool_maxsize = pool_maxsize77 self._pool_block = pool_block7876 self.init_poolmanager(pool_connections, pool_maxsize)79 self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)8081 def __getstate__(self):82 return dict((attr, getattr(self, attr, None)) for attr in83 self.__attrs__)
3 unmodified lines
87 setattr(self, attr, value)8889 self.init_poolmanager(self._pool_connections, self._pool_maxsize)9088 def init_poolmanager(self, connections, maxsize):91 def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK):92 """Initializes a urllib3 PoolManager. This method should not be called93 from user code, and is only exposed for use when subclassing the94 :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.9596 :param connections: The number of urllib3 connection pools to cache.97 :param maxsize: The maximum number of connections to save in the pool.98 :param block: Block when no free connections are available.99 """100 # save these values for pickling101 self._pool_connections = connections102 self._pool_maxsize = maxsize103 self._pool_block = block104100 self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize)105 self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize,106 block=block)107108 def cert_verify(self, conn, url, verify, cert):109 """Verify a SSL certificate. This method should not be called from user110 code, and is only exposed for use when subclassing the
229 unmodified lines