本文整理匯總了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))
示例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
示例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()
示例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
示例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()
示例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")
示例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")
示例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)
示例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)