MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / close

Method close

pymongo/asynchronous/mongo_client.py:1725–1759  ·  view source on GitHub ↗

Cleanup client resources and disconnect from MongoDB. End all server sessions created by this client by sending one or more endSessions commands. Close all sockets in the connection pools and stop the monitor threads. .. versionchanged:: 4.0 Once closed,

(self)

Source from the content-addressed store, hash-verified

1723 pass
1724
1725 async def close(self) -> None:
1726 """Cleanup client resources and disconnect from MongoDB.
1727
1728 End all server sessions created by this client by sending one or more
1729 endSessions commands.
1730
1731 Close all sockets in the connection pools and stop the monitor threads.
1732
1733 .. versionchanged:: 4.0
1734 Once closed, the client cannot be used again and any attempt will
1735 raise :exc:`~pymongo.errors.InvalidOperation`.
1736
1737 .. versionchanged:: 3.6
1738 End all server sessions created by this client.
1739 """
1740 if self._topology is None:
1741 return
1742 session_ids = self._topology.pop_all_sessions()
1743 if session_ids:
1744 await self._end_sessions(session_ids)
1745 # Stop the periodic task thread and then send pending killCursor
1746 # requests before closing the topology.
1747 self._kill_cursors_executor.close()
1748 await self._process_kill_cursors()
1749 await self._topology.close()
1750 if self._encrypter:
1751 # TODO: PYTHON-1921 Encrypted MongoClients cannot be re-opened.
1752 await self._encrypter.close()
1753 self._closed = True
1754 if not _IS_SYNC:
1755 await asyncio.gather(
1756 self._topology.cleanup_monitors(), # type: ignore[func-returns-value]
1757 self._kill_cursors_executor.join(), # type: ignore[func-returns-value]
1758 return_exceptions=True,
1759 )
1760
1761 if not _IS_SYNC:
1762 # Add support for contextlib.aclosing.

Callers 11

_run_scenarioFunction · 0.95
fail_pointMethod · 0.95
_connectMethod · 0.95
_check_user_providedMethod · 0.95
test_repr_srv_hostMethod · 0.95
__aexit__Method · 0.95
_cleanup_cursor_lockMethod · 0.45

Calls 5

_end_sessionsMethod · 0.95
_process_kill_cursorsMethod · 0.95
pop_all_sessionsMethod · 0.45
cleanup_monitorsMethod · 0.45
joinMethod · 0.45

Tested by 7

_run_scenarioFunction · 0.76
fail_pointMethod · 0.76
test_repr_srv_hostMethod · 0.76