Skip to content

Commit 9de93d9

Browse files
author
A. Jesse Jiryu Davis
committed
Change default for Connection and RSC, fix bugs when max_pool_size=None. PYTHON-436
1 parent 5a88c6c commit 9de93d9

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed

pymongo/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Connection(MongoClient):
4444
"""Connection to MongoDB.
4545
"""
4646

47-
def __init__(self, host=None, port=None, max_pool_size=10,
47+
def __init__(self, host=None, port=None, max_pool_size=None,
4848
network_timeout=None, document_class=dict,
4949
tz_aware=False, _connect=True, **kwargs):
5050
"""Create a new connection to a single MongoDB instance at *host:port*.
@@ -87,7 +87,7 @@ def __init__(self, host=None, port=None, max_pool_size=10,
8787
- `max_pool_size` (optional): The maximum number of connections
8888
that the pool will open simultaneously. If this is set, operations
8989
will block if there are `max_pool_size` outstanding connections
90-
from the pool. Defaults to 100.
90+
from the pool. By default the pool size is unlimited.
9191
- `network_timeout` (optional): timeout (in seconds) to use
9292
for socket operations - default is no timeout
9393
- `document_class` (optional): default class to use for

pymongo/mongo_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ def __init__(self, host=None, port=None, max_pool_size=100,
269269
options[option] = value
270270
options.update(opts)
271271

272-
self.__max_pool_size = common.validate_positive_integer(
273-
'max_pool_size', max_pool_size)
272+
self.__max_pool_size = common.validate_positive_integer_or_none(
273+
'max_pool_size', max_pool_size)
274274

275275
self.__cursor_manager = CursorManager(self)
276276

pymongo/mongo_replica_set_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ def __init__(self, hosts_or_uri=None, max_pool_size=100,
634634
self.__index_cache = {}
635635
self.__auth_credentials = {}
636636

637-
self.__max_pool_size = common.validate_positive_integer(
638-
'max_pool_size', max_pool_size)
637+
self.__max_pool_size = common.validate_positive_integer_or_none(
638+
'max_pool_size', max_pool_size)
639639
self.__tz_aware = common.validate_boolean('tz_aware', tz_aware)
640640
self.__document_class = document_class
641641
self.__monitor = None

pymongo/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def __init__(self, pair, max_size, net_timeout, conn_timeout, use_ssl,
177177
# Count the number of calls to start_request() per thread or greenlet
178178
self._request_counter = thread_util.Counter(use_greenlets)
179179

180-
if self.wait_queue_multiple is None:
180+
if self.wait_queue_multiple is None or self.max_size is None:
181181
max_waiters = None
182182
else:
183183
max_waiters = self.max_size * self.wait_queue_multiple

pymongo/replica_set_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ReplicaSetConnection(MongoReplicaSetClient):
4141
"""Connection to a MongoDB replica set.
4242
"""
4343

44-
def __init__(self, hosts_or_uri=None, max_pool_size=10,
44+
def __init__(self, hosts_or_uri=None, max_pool_size=None,
4545
document_class=dict, tz_aware=False, **kwargs):
4646
"""Create a new connection to a MongoDB replica set.
4747
@@ -83,7 +83,7 @@ def __init__(self, hosts_or_uri=None, max_pool_size=10,
8383
- `max_pool_size` (optional): The maximum number of connections
8484
each pool will open simultaneously. If this is set, operations
8585
will block if there are `max_pool_size` outstanding connections
86-
from the pool. Defaults to 100.
86+
from the pool. By default the pool size is unlimited.
8787
- `document_class` (optional): default class to use for
8888
documents returned from queries on this connection
8989
- `tz_aware` (optional): if ``True``,

test/test_legacy_connections.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TestConnection(unittest.TestCase):
3434
def test_connection(self):
3535
c = Connection(host, port)
3636
self.assertTrue(c.auto_start_request)
37+
self.assertEqual(None, c.max_pool_size)
3738
self.assertFalse(c.slave_okay)
3839
self.assertFalse(c.safe)
3940
self.assertEqual({}, c.get_lasterror_options())
@@ -67,6 +68,7 @@ class TestReplicaSetConnection(TestReplicaSetClientBase):
6768
def test_replica_set_connection(self):
6869
c = ReplicaSetConnection(pair, replicaSet=self.name)
6970
self.assertTrue(c.auto_start_request)
71+
self.assertEqual(None, c.max_pool_size)
7072
self.assertFalse(c.slave_okay)
7173
self.assertFalse(c.safe)
7274
self.assertEqual({}, c.get_lasterror_options())

0 commit comments

Comments
 (0)