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


Python KazooState.SUSPENDED屬性代碼示例

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


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

示例1: _lock_listener

# 需要導入模塊: from kazoo.client import KazooState [as 別名]
# 或者: from kazoo.client.KazooState import SUSPENDED [as 別名]
def _lock_listener(self, state):
        """
        Listener to handle ZK disconnection/reconnection. Since I don't know of safe way to check if a lock is still in
        ZK after a reconnect, we simply release the lock and try and re-acquire it.

        Args:
            state (kazoo.client.KazooState): The state of the ZK connection

        Returns:
            None
        """

        if state in [KazooState.LOST, KazooState.SUSPENDED]:
            self._logger.warn(u'Disconnected from Zookeeper, waiting to reconnect lock for {}'.format(str(self)))
            self._locked = False
        elif state == KazooState.CONNECTED:
            self._logger.warn(
                    u'Reconnected to Zookeeper, trying to release and re-acquire lock for {}'.format(str(self)))
            self._context.zookeeper_client.handler.spawn(self._release_and_reacquire)
        else:
            self._logger.warn(u'Got unknown state "{}" from Zookeeper'.format(state)) 
開發者ID:yahoo,項目名稱:panoptes,代碼行數:23,代碼來源:lock.py

示例2: event_listener

# 需要導入模塊: from kazoo.client import KazooState [as 別名]
# 或者: from kazoo.client.KazooState import SUSPENDED [as 別名]
def event_listener(self, state):
        if state == KazooState.LOST or state == KazooState.SUSPENDED:
            logger.info('ZK state transitioned to %s. Resetting master status.', state)

            # cancel pending attempts to acquire lock which will break and leave
            # us in bad state
            self.lock.cancel()

            # make us try to re-acquire lock during next iteration when we're connected
            if self.lock.is_acquired:
                self.lock.is_acquired = False

            # make us try to rejoin the party during next iteration when we're connected
            if self.party.participating:
                self.party.participating = False

            # in the meantime we're not master
            self.is_master = None 
開發者ID:linkedin,項目名稱:iris,代碼行數:20,代碼來源:kazoo.py

示例3: state_listener

# 需要導入模塊: from kazoo.client import KazooState [as 別名]
# 或者: from kazoo.client.KazooState import SUSPENDED [as 別名]
def state_listener(self, state):
        '''
        Restarts the session if we get anything besides CONNECTED
        '''
        if state == KazooState.SUSPENDED:
            self.set_valid(False)
            self.call_error(self.BAD_CONNECTION)
        elif state == KazooState.LOST and not self.do_not_restart:
            self.threaded_start()
        elif state == KazooState.CONNECTED:
            # This is going to throw a SUSPENDED kazoo error
            # which will cause the sessions to be wiped and re established.
            # Used b/c of massive connection pool issues
            self.zoo_client.stop() 
開發者ID:istresearch,項目名稱:scrapy-cluster,代碼行數:16,代碼來源:zookeeper_watcher.py

示例4: _on_conn_change

# 需要導入模塊: from kazoo.client import KazooState [as 別名]
# 或者: from kazoo.client.KazooState import SUSPENDED [as 別名]
def _on_conn_change(self, state):

        logger.debug('state changed: {state}'.format(state=state,))

        with self.state_lock:
            if state == KazooState.LOST or state == KazooState.SUSPENDED:
                self.connected = False 
開發者ID:bsc-s2,項目名稱:pykit,代碼行數:9,代碼來源:zktx.py

示例5: connection_listener

# 需要導入模塊: from kazoo.client import KazooState [as 別名]
# 或者: from kazoo.client.KazooState import SUSPENDED [as 別名]
def connection_listener(self, state: KazooState) -> None:
        self.log.warning(f"Zookeeper connection transitioned to: {state}")
        if state == KazooState.SUSPENDED:
            self.log.warning(
                "Zookeeper connection suspended, waiting to see if it recovers."
            )
            if not self.waiting_for_reconnect:
                self.waiting_for_reconnect = True
                reconnection_checker = PaastaThread(target=self.reconnection_listener)
                reconnection_checker.daemon = True
                reconnection_checker.start()
        elif state == KazooState.LOST:
            self.log.error("Leadership lost, quitting!")
            self._terminate() 
開發者ID:Yelp,項目名稱:paasta,代碼行數:16,代碼來源:leader.py

示例6: test_connection_listener

# 需要導入模塊: from kazoo.client import KazooState [as 別名]
# 或者: from kazoo.client.KazooState import SUSPENDED [as 別名]
def test_connection_listener(self):
        with mock.patch(
            "paasta_tools.deployd.leader.PaastaThread", autospec=True
        ) as mock_paasta_thread:
            self.election.connection_listener(KazooState.CONNECTED)
            self.election.connection_listener(KazooState.SUSPENDED)
            mock_paasta_thread.assert_called_with(
                target=self.election.reconnection_listener
            )
            assert self.election.waiting_for_reconnect
            self.election.connection_listener(KazooState.LOST)
            self.mock_control.put.assert_called_with("ABORT") 
開發者ID:Yelp,項目名稱:paasta,代碼行數:14,代碼來源:test_leader.py

示例7: test_reconnection_listener

# 需要導入模塊: from kazoo.client import KazooState [as 別名]
# 或者: from kazoo.client.KazooState import SUSPENDED [as 別名]
def test_reconnection_listener(self):
        self.mock_client.state = KazooState.CONNECTED
        self.election.reconnection_listener()
        assert not self.election.waiting_for_reconnect
        assert not self.mock_control.put.called

        self.mock_client.state = KazooState.SUSPENDED
        self.election.waiting_for_reconnect = True
        with mock.patch("time.sleep", autospec=True):
            self.election.reconnection_listener()
        assert self.election.waiting_for_reconnect
        self.mock_control.put.assert_called_with("ABORT") 
開發者ID:Yelp,項目名稱:paasta,代碼行數:14,代碼來源:test_leader.py

示例8: session_listener

# 需要導入模塊: from kazoo.client import KazooState [as 別名]
# 或者: from kazoo.client.KazooState import SUSPENDED [as 別名]
def session_listener(self, state):
        if state in [KazooState.SUSPENDED, KazooState.LOST]:
            self.cluster_watcher(None) 
開發者ID:zalando,項目名稱:patroni,代碼行數:5,代碼來源:zookeeper.py

示例9: test_session_listener

# 需要導入模塊: from kazoo.client import KazooState [as 別名]
# 或者: from kazoo.client.KazooState import SUSPENDED [as 別名]
def test_session_listener(self):
        self.zk.session_listener(KazooState.SUSPENDED) 
開發者ID:zalando,項目名稱:patroni,代碼行數:4,代碼來源:test_zookeeper.py


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