MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / close

Method close

pymongo/asynchronous/topology.py:718–784  ·  view source on GitHub ↗

Clear pools and terminate monitors. Topology does not reopen on demand. Any further operations will raise :exc:`~.errors.InvalidOperation`.

(self)

Source from the content-addressed store, hash-verified

716 raise
717
718 async def close(self) -> None:
719 """Clear pools and terminate monitors. Topology does not reopen on
720 demand. Any further operations will raise
721 :exc:`~.errors.InvalidOperation`.
722 """
723 async with self._lock:
724 old_td = self._description
725 for server in self._servers.values():
726 await server.close()
727 if not _IS_SYNC:
728 self._monitor_tasks.append(server._monitor)
729
730 # Mark all servers Unknown.
731 self._description = self._description.reset()
732 for address, sd in self._description.server_descriptions().items():
733 if address in self._servers:
734 self._servers[address].description = sd
735
736 # Stop SRV polling thread.
737 if self._srv_monitor:
738 await self._srv_monitor.close()
739 if not _IS_SYNC:
740 self._monitor_tasks.append(self._srv_monitor)
741
742 self._opened = False
743 self._closed = True
744
745 # Publish only after releasing the lock.
746 if self._publish_tp:
747 assert self._events is not None
748 assert self._listeners is not None
749 self._description = TopologyDescription(
750 TOPOLOGY_TYPE.Unknown,
751 {},
752 self._description.replica_set_name,
753 self._description.max_set_version,
754 self._description.max_election_id,
755 self._description._topology_settings,
756 )
757 self._events.put(
758 (
759 self._listeners.publish_topology_description_changed,
760 (
761 old_td,
762 self._description,
763 self._topology_id,
764 ),
765 )
766 )
767 self._events.put((self._listeners.publish_topology_closed, (self._topology_id,)))
768 if _SDAM_LOGGER.isEnabledFor(logging.DEBUG):
769 _debug_log(
770 _SDAM_LOGGER,
771 message=_SDAMStatusMessage.TOPOLOGY_CHANGE,
772 topologyId=self._topology_id,
773 previousDescription=repr(old_td),
774 newDescription=repr(self._description),
775 )

Callers 2

openMethod · 0.45
_process_changeMethod · 0.45

Calls 9

TopologyDescriptionClass · 0.90
_debug_logFunction · 0.90
valuesMethod · 0.80
itemsMethod · 0.80
server_descriptionsMethod · 0.80
process_events_queueFunction · 0.70
resetMethod · 0.45
putMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected