Merge pull request #1356 from Zoramite/ConnectionPoolArgs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Adding an argument to the adapter for passing a block argument
authored by Kenneth Reitz · committed by Kenneth Reitz · parents f4e7809, c03e142 · Browse files · 1 file·+15 added−6 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+15 added−6 removed
- other:+15 added−6 removed
Provenance
- Commit
8f42369- Tree
f5ca966- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
f4e7809- Parent 2
c03e142
1 file changed+15 added−6 removed
modified:requests/adapters.py+15 added-6 removed
23 unmodified lines24 from .cookies import extract_cookies_to_jar25 from .exceptions import ConnectionError, Timeout, SSLError26 from .auth import _basic_auth_str27 28+DEFAULT_POOLBLOCK = False29 DEFAULT_POOLSIZE = 1030 DEFAULT_RETRIES = 031 32 20 unmodified lines53 54 :param pool_connections: The number of urllib3 connection pools to cache.55 :param pool_maxsize: The maximum number of connections to save in the pool.56 :param max_retries: The maximum number of retries each connection should attempt.57+ :param pool_block: Whether the connection pool should block for connections.58 59 Usage::60 61 >>> import requests62 >>> s = requests.Session()63 >>> a = requests.adapters.HTTPAdapter()64 >>> s.mount('http://', a)65 """64- __attrs__ = ['max_retries', 'config', '_pool_connections', '_pool_maxsize']66+ __attrs__ = ['max_retries', 'config', '_pool_connections', '_pool_maxsize',67+ '_pool_block']68 69 def __init__(self, pool_connections=DEFAULT_POOLSIZE,67- pool_maxsize=DEFAULT_POOLSIZE, max_retries=DEFAULT_RETRIES):70+ pool_maxsize=DEFAULT_POOLSIZE, max_retries=DEFAULT_RETRIES,71+ pool_block=DEFAULT_POOLBLOCK):72 self.max_retries = max_retries73 self.config = {}74 75 super(HTTPAdapter, self).__init__()76 77 self._pool_connections = pool_connections78 self._pool_maxsize = pool_maxsize79+ self._pool_block = pool_block80 76- self.init_poolmanager(pool_connections, pool_maxsize)81+ self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)82 83 def __getstate__(self):84 return dict((attr, getattr(self, attr, None)) for attr in85 self.__attrs__)1 unmodified line87 def __setstate__(self, state):88 for attr, value in state.items():89 setattr(self, attr, value)90 86- self.init_poolmanager(self._pool_connections, self._pool_maxsize)91+ self.init_poolmanager(self._pool_connections, self._pool_maxsize,92+ block=self._pool_block)93 88- def init_poolmanager(self, connections, maxsize):94+ def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK):95 """Initializes a urllib3 PoolManager. This method should not be called96 from user code, and is only exposed for use when subclassing the97 :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.98 99 :param connections: The number of urllib3 connection pools to cache.100 :param maxsize: The maximum number of connections to save in the pool.101+ :param block: Block when no free connections are available.102 """103 # save these values for pickling104 self._pool_connections = connections105 self._pool_maxsize = maxsize106+ self._pool_block = block107 100- self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize)108+ self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize,109+ block=block)110 111 def cert_verify(self, conn, url, verify, cert):112 """Verify a SSL certificate. This method should not be called from user113 code, and is only exposed for use when subclassing the229 unmodified lines