PYTHON-4347 [v4.8] Improve performance by only calling get_topology once (#1676)

This commit is contained in:
Shane Harvey 2024-06-12 13:20:52 -07:00 committed by GitHub
parent 2fa651c739
commit e059fdef6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -862,6 +862,7 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]):
server_monitoring_mode=options.server_monitoring_mode,
)
self._opened = False
self._init_background()
if connect:
@ -1245,9 +1246,11 @@ class MongoClient(common.BaseObject, Generic[_DocumentType]):
If this client was created with "connect=False", calling _get_topology
launches the connection process in the background.
"""
self._topology.open()
with self.__lock:
self._kill_cursors_executor.open()
if not self._opened:
self._topology.open()
with self.__lock:
self._kill_cursors_executor.open()
self._opened = True
return self._topology
@contextlib.contextmanager