Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge.

  • Loading branch information...
commit 86cf15473413ecf15c513ada57e36ff25ceb9776 2 parents 40bad3b + 5de8335
@shazow authored
View
3  CHANGES.rst
@@ -11,6 +11,9 @@ Changes
* Use ``select.poll`` instead of ``select.select`` for platforms that support
it.
+* Use ``Queue.LifoQueue`` instead of ``Queue.Queue`` for more aggressive
+ connection reusing. Configurable by overriding ``ConnectionPool.QueueCls``.
+
* Fixed ``ImportError`` during install when ``ssl`` module is not available.
(Issue #41)
View
10 test/with_dummyserver/test_connectionpool.py
@@ -221,6 +221,16 @@ def test_connection_count(self):
self.assertEqual(pool.num_connections, 1)
self.assertEqual(pool.num_requests, 3)
+ def test_connection_count_bigpool(self):
+ http_pool = HTTPConnectionPool(self.host, self.port, maxsize=16)
+
+ http_pool.request('GET', '/')
+ http_pool.request('GET', '/')
+ http_pool.request('GET', '/')
+
+ self.assertEqual(http_pool.num_connections, 1)
+ self.assertEqual(http_pool.num_requests, 3)
+
def test_partial_response(self):
pool = HTTPConnectionPool(self.host, self.port, maxsize=1)
View
7 urllib3/connectionpool.py
@@ -24,9 +24,9 @@
from httplib import HTTP_PORT, HTTPS_PORT
try: # Python 3
- from queue import Queue, Empty, Full
+ from queue import LifoQueue, Empty, Full
except ImportError:
- from Queue import Queue, Empty, Full
+ from Queue import LifoQueue, Empty, Full
try: # Compiled with SSL?
@@ -114,6 +114,7 @@ class ConnectionPool(object):
"""
scheme = None
+ QueueCls = LifoQueue
def __init__(self, host, port=None):
self.host = host
@@ -171,7 +172,7 @@ def __init__(self, host, port=None, strict=False, timeout=None, maxsize=1,
self.strict = strict
self.timeout = timeout
- self.pool = Queue(maxsize)
+ self.pool = self.QueueCls(maxsize)
self.block = block
self.headers = headers or {}
Please sign in to comment.
Something went wrong with that request. Please try again.