PYTHON-1040 - Add and use client._disconnect
This commit is contained in:
parent
65c0aed610
commit
0a5ef8de6e
@ -120,7 +120,7 @@ class CommandCursor(object):
|
||||
# Don't send kill cursors to another server after a "not master"
|
||||
# error. It's completely pointless.
|
||||
self.__killed = True
|
||||
client.disconnect()
|
||||
client._disconnect()
|
||||
raise
|
||||
self.__id = response["cursor_id"]
|
||||
if self.__id == 0:
|
||||
|
||||
@ -1038,7 +1038,7 @@ class Cursor(object):
|
||||
self.__killed = True
|
||||
# Make sure exhaust socket is returned immediately, if necessary.
|
||||
self.__die()
|
||||
client.disconnect()
|
||||
client._disconnect()
|
||||
raise
|
||||
|
||||
self.__id = response["cursor_id"]
|
||||
|
||||
@ -436,8 +436,8 @@ class Database(common.BaseObject):
|
||||
if check:
|
||||
msg = "command %s on namespace %s failed: %%s" % (
|
||||
repr(command).replace("%", "%%"), self.name + '.$cmd')
|
||||
helpers._check_command_response(result, self.connection.disconnect,
|
||||
msg, allowable_errors)
|
||||
helpers._check_command_response(
|
||||
result, self.connection._disconnect, msg, allowable_errors)
|
||||
|
||||
return result, cursor.conn_id
|
||||
|
||||
@ -756,7 +756,7 @@ class Database(common.BaseObject):
|
||||
if error_msg is None:
|
||||
return None
|
||||
if error_msg.startswith("not master"):
|
||||
self.__connection.disconnect()
|
||||
self.__connection._disconnect()
|
||||
return error
|
||||
|
||||
def last_status(self):
|
||||
|
||||
@ -197,6 +197,10 @@ class MasterSlaveConnection(BaseObject):
|
||||
.. seealso:: Module :mod:`~pymongo.mongo_client`
|
||||
.. versionadded:: 1.10.1
|
||||
"""
|
||||
self._disconnect()
|
||||
|
||||
def _disconnect(self):
|
||||
"""Internal disconnect helper."""
|
||||
self.__master.disconnect()
|
||||
for slave in self.__slaves:
|
||||
slave.disconnect()
|
||||
@ -207,7 +211,7 @@ class MasterSlaveConnection(BaseObject):
|
||||
.. seealso:: :meth:`end_request`
|
||||
.. versionadded:: 2.8
|
||||
"""
|
||||
self.disconnect()
|
||||
self._disconnect()
|
||||
|
||||
def set_cursor_manager(self, manager_class):
|
||||
"""Set the cursor manager for this connection.
|
||||
|
||||
@ -1089,7 +1089,7 @@ class MongoClient(common.BaseObject):
|
||||
warnings.warn("disconnect is deprecated in this version of PyMongo "
|
||||
"and removed in PyMongo 3. Use close() instead.",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
self.close()
|
||||
self._disconnect()
|
||||
|
||||
def close(self):
|
||||
"""Disconnect from MongoDB.
|
||||
@ -1103,6 +1103,10 @@ class MongoClient(common.BaseObject):
|
||||
.. seealso:: :meth:`end_request`
|
||||
.. versionadded:: 2.1
|
||||
"""
|
||||
self._disconnect()
|
||||
|
||||
def _disconnect(self):
|
||||
"""Internal disconnect helper."""
|
||||
self.__connecting_lock.acquire()
|
||||
member, self.__member = self.__member, None
|
||||
self.__connecting_lock.release()
|
||||
|
||||
@ -1439,6 +1439,10 @@ class MongoReplicaSetClient(common.BaseObject):
|
||||
"""Disconnect from the replica set primary, unpin all members, and
|
||||
refresh our view of the replica set.
|
||||
"""
|
||||
self._disconnect()
|
||||
|
||||
def _disconnect(self):
|
||||
"""Internal disconnect helper."""
|
||||
rs_state = self.__rs_state
|
||||
if rs_state.primary_member:
|
||||
rs_state.primary_member.reset()
|
||||
@ -1523,7 +1527,7 @@ class MongoReplicaSetClient(common.BaseObject):
|
||||
assert response["number_returned"] == 1
|
||||
result = response["data"][0]
|
||||
|
||||
helpers._check_command_response(result, self.disconnect)
|
||||
helpers._check_command_response(result, self._disconnect)
|
||||
|
||||
# write commands - skip getLastError checking
|
||||
if is_command:
|
||||
@ -1534,7 +1538,7 @@ class MongoReplicaSetClient(common.BaseObject):
|
||||
if error_msg is None:
|
||||
return result
|
||||
if error_msg.startswith("not master"):
|
||||
self.disconnect()
|
||||
self._disconnect()
|
||||
raise AutoReconnect(error_msg)
|
||||
|
||||
code = result.get("code")
|
||||
@ -1645,7 +1649,7 @@ class MongoReplicaSetClient(common.BaseObject):
|
||||
except(ConnectionFailure, socket.error), why:
|
||||
member.discard_socket(sock_info)
|
||||
if _connection_to_use in (None, -1):
|
||||
self.disconnect()
|
||||
self._disconnect()
|
||||
raise AutoReconnect(str(why))
|
||||
except:
|
||||
sock_info.close()
|
||||
@ -1758,7 +1762,7 @@ class MongoReplicaSetClient(common.BaseObject):
|
||||
except AutoReconnect:
|
||||
if _connection_to_use in (-1, rs_state.writer):
|
||||
# Primary's down. Refresh.
|
||||
self.disconnect()
|
||||
self._disconnect()
|
||||
raise
|
||||
|
||||
# To provide some monotonic consistency, we use the same member as
|
||||
@ -1780,7 +1784,7 @@ class MongoReplicaSetClient(common.BaseObject):
|
||||
self.__try_read(pinned_member, msg, **kwargs))
|
||||
except AutoReconnect, why:
|
||||
if _must_use_master or mode == ReadPreference.PRIMARY:
|
||||
self.disconnect()
|
||||
self._disconnect()
|
||||
raise
|
||||
else:
|
||||
errors.append(str(why))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user