當前位置: 首頁>>代碼示例>>Python>>正文


Python Topology.reset_server方法代碼示例

本文整理匯總了Python中pymongo.topology.Topology.reset_server方法的典型用法代碼示例。如果您正苦於以下問題:Python Topology.reset_server方法的具體用法?Python Topology.reset_server怎麽用?Python Topology.reset_server使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pymongo.topology.Topology的用法示例。


在下文中一共展示了Topology.reset_server方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: MongoClient

# 需要導入模塊: from pymongo.topology import Topology [as 別名]
# 或者: from pymongo.topology.Topology import reset_server [as 別名]

#.........這裏部分代碼省略.........
        """
        manager = manager_class(self)
        if not isinstance(manager, CursorManager):
            raise TypeError("manager_class must be a subclass of "
                            "CursorManager")

        self.__cursor_manager = manager

    def _get_topology(self):
        """Get the internal :class:`~pymongo.topology.Topology` object.

        If this client was created with "connect=False", calling _get_topology
        launches the connection process in the background.
        """
        self._topology.open()
        return self._topology

    @contextlib.contextmanager
    def _get_socket(self, selector):
        server = self._get_topology().select_server(selector)
        try:
            with server.get_socket(self.__all_credentials) as sock_info:
                yield sock_info
        except NetworkTimeout:
            # The socket has been closed. Don't reset the server.
            # Server Discovery And Monitoring Spec: "When an application
            # operation fails because of any network error besides a socket
            # timeout...."
            raise
        except NotMasterError:
            # "When the client sees a "not master" error it MUST replace the
            # server's description with type Unknown. It MUST request an
            # immediate check of the server."
            self._reset_server_and_request_check(server.description.address)
            raise
        except ConnectionFailure:
            # "Client MUST replace the server's description with type Unknown
            # ... MUST NOT request an immediate check of the server."
            self.__reset_server(server.description.address)
            raise

    def _socket_for_writes(self):
        return self._get_socket(writable_server_selector)

    @contextlib.contextmanager
    def _socket_for_reads(self, read_preference):
        preference = read_preference or ReadPreference.PRIMARY
        # Get a socket for a server matching the read preference, and yield
        # sock_info, slave_ok. Server Selection Spec: "slaveOK must be sent to
        # mongods with topology type Single. If the server type is Mongos,
        # follow the rules for passing read preference to mongos, even for
        # topology type Single."
        # Thread safe: if the type is single it cannot change.
        topology = self._get_topology()
        single = topology.description.topology_type == TOPOLOGY_TYPE.Single
        with self._get_socket(read_preference) as sock_info:
            slave_ok = (single and not sock_info.is_mongos) or (
                preference != ReadPreference.PRIMARY)
            yield sock_info, slave_ok

    def _send_message_with_response(self, operation, read_preference=None,
                                    exhaust=False, address=None):
        """Send a message to MongoDB and return a Response.

        :Parameters:
          - `operation`: a _Query or _GetMore object.
開發者ID:ToontownBattlefront,項目名稱:Toontown-Battlefront,代碼行數:70,代碼來源:mongo_client.py


注:本文中的pymongo.topology.Topology.reset_server方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。