PYTHON-847 Remove disconnect(), synonym of MongoClient.close().

close() seems more standard among MongoDB drivers.
This commit is contained in:
A. Jesse Jiryu Davis 2015-02-24 23:48:17 -05:00
parent e7a1b261cd
commit 7f42430978
12 changed files with 25 additions and 33 deletions

View File

@ -6,7 +6,6 @@
.. autoclass:: pymongo.mongo_client.MongoClient(host='localhost', port=27017, max_pool_size=100, document_class=dict, tz_aware=False, **kwargs)
.. automethod:: disconnect
.. automethod:: close
.. describe:: c[db_name] || c.db_name

View File

@ -6,7 +6,6 @@
.. autoclass:: pymongo.mongo_replica_set_client.MongoReplicaSetClient(hosts_or_uri, max_pool_size=100, document_class=dict, tz_aware=False, **kwargs)
.. automethod:: disconnect
.. automethod:: close
.. describe:: c[db_name] || c.db_name

View File

@ -69,7 +69,7 @@ A thread that waits more than 100ms (in this example) for a socket raises
important to bound the duration of operations during a load spike than it is to
complete every operation.
When :meth:`~pymongo.mongo_client.MongoClient.disconnect` is called by any
When :meth:`~pymongo.mongo_client.MongoClient.close` is called by any
thread, all sockets are closed.
Does PyMongo support Python 3?

View File

@ -241,6 +241,9 @@ class MongoClient(common.BaseObject):
The ``copy_database`` method is removed, see the
:doc:`copy_database examples </examples/copydb>` for alternatives.
The :meth:`MongoClient.disconnect` method is removed; it was a
synonym for :meth:`~pymongo.MongoClient.close`.
:class:`~pymongo.mongo_client.MongoClient` no longer returns an
instance of :class:`~pymongo.database.Database` for attribute names
with leading underscores. You must use dict-style lookups instead::
@ -643,24 +646,15 @@ class MongoClient(common.BaseObject):
except ConnectionFailure:
return False
def disconnect(self):
def close(self):
"""Disconnect from MongoDB.
Disconnecting will close all underlying sockets in the connection
pools. If this instance is used again it will be automatically
re-opened.
Close all sockets in the connection pools and stop the monitor threads.
If this instance is used again it will be automatically re-opened and
the threads restarted.
"""
self._topology.close()
def close(self):
"""Alias for :meth:`disconnect`
Disconnecting will close all underlying sockets in the connection
pools. If this instance is used again it will be automatically
re-opened.
"""
self.disconnect()
def set_cursor_manager(self, manager_class):
"""Set this client's cursor manager.
@ -1079,7 +1073,7 @@ class MongoClient(common.BaseObject):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.disconnect()
self.close()
def __iter__(self):
return self

View File

@ -76,7 +76,7 @@ class Monitor(object):
self._executor.open()
def close(self):
"""Disconnect and stop monitoring.
"""Close and stop monitoring.
open() restarts the monitor after closing.
"""

View File

@ -40,7 +40,7 @@ ndocs = 20
collection.drop()
collection.insert_many([{'i': i} for i in range(ndocs)])
client.disconnect() # Discard main thread's request socket.
client.close() # Discard main thread's request socket.
try:
from mod_wsgi import version as mod_wsgi_version

View File

@ -302,16 +302,16 @@ class TestClient(IntegrationTest):
self.assertNotIn("pymongo_test", dbs)
self.assertNotIn("pymongo_test2", dbs)
def test_disconnect(self):
def test_close(self):
coll = self.client.pymongo_test.bar
self.client.disconnect()
self.client.disconnect()
self.client.close()
self.client.close()
coll.count()
self.client.disconnect()
self.client.disconnect()
self.client.close()
self.client.close()
coll.count()
@ -975,7 +975,7 @@ class TestClientProperties(MockClientTest):
c.set_wire_version_range('a:1', 0, 0)
c.set_wire_version_range('b:2', 0, 0)
c.set_wire_version_range('c:3', 0, 0)
c.disconnect()
c.close()
c.db.command('ismaster')
used_host = '%s:%s' % (c.host, c.port)
expected_min, expected_max = c.mock_wire_versions[used_host]
@ -1081,7 +1081,7 @@ class TestMongoClientFailover(MockClientTest):
c.kill_host('a:1')
c.mock_primary = 'b:2'
c.disconnect()
c.close()
self.assertEqual(0, len(c.nodes))
t = c._get_topology()

View File

@ -539,7 +539,7 @@ class TestDatabase(IntegrationTest):
other_db.test.insert_one, {})
# Close all sockets.
client.disconnect()
client.close()
# We should still be able to write to the regular user's db.
self.assertTrue(users_db.test.delete_many({}))

View File

@ -85,7 +85,7 @@ class TestMongosHA(MockClientTest):
wait_until(lambda: len(client.nodes) == 3, 'connect to all mongoses')
# Trigger reconnect.
client.disconnect()
client.close()
do_simple_op(client, nthreads)
wait_until(lambda: len(client.nodes) == 3,

View File

@ -104,7 +104,7 @@ class NonUnique(MongoThread):
class Disconnect(MongoThread):
def run_mongo_thread(self):
for _ in range(N):
self.client.disconnect()
self.client.close()
class SocketGetter(MongoThread):

View File

@ -55,7 +55,7 @@ class TestSecondaryBecomesStandalone(MockClientTest):
c.kill_host('b:2')
# Force reconnect.
c.disconnect()
c.close()
with self.assertRaises(AutoReconnect):
c.db.command('ismaster')
@ -152,7 +152,7 @@ class TestSecondaryAdded(MockClientTest):
c.mock_members.append('c:3')
c.mock_ismaster_hosts.append('c:3')
c.disconnect()
c.close()
c.db.command('ismaster')
self.assertEqual('a', c.host)

View File

@ -125,7 +125,7 @@ class Disconnect(threading.Thread):
def run(self):
for _ in range(self.n):
self.client.disconnect()
self.client.close()
self.passed = True
@ -189,7 +189,7 @@ class TestThreads(IntegrationTest):
self.db.test.insert_many([{"x": i} for i in range(1000)])
# Start 10 threads that execute a query, and 10 threads that call
# client.disconnect() 10 times in a row.
# client.close() 10 times in a row.
threads = [SaveAndFind(self.db.test) for _ in range(10)]
threads.extend(Disconnect(self.db.connection, 10) for _ in range(10))