本文整理匯總了Python中kazoo.protocol.connection.ConnectionHandler.close方法的典型用法代碼示例。如果您正苦於以下問題:Python ConnectionHandler.close方法的具體用法?Python ConnectionHandler.close怎麽用?Python ConnectionHandler.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類kazoo.protocol.connection.ConnectionHandler
的用法示例。
在下文中一共展示了ConnectionHandler.close方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: KazooClient
# 需要導入模塊: from kazoo.protocol.connection import ConnectionHandler [as 別名]
# 或者: from kazoo.protocol.connection.ConnectionHandler import close [as 別名]
#.........這裏部分代碼省略.........
self.logger.info("Zookeeper connection lost")
# Connection lost
self._live.clear()
self._notify_pending(state)
self._make_state_change(KazooState.SUSPENDED)
self._reset_watchers()
def _notify_pending(self, state):
"""Used to clear a pending response queue and request queue
during connection drops."""
if state == KeeperState.AUTH_FAILED:
exc = AuthFailedError()
elif state == KeeperState.EXPIRED_SESSION:
exc = SessionExpiredError()
else:
exc = ConnectionLoss()
while True:
try:
request, async_object, xid = self._pending.popleft()
if async_object:
async_object.set_exception(exc)
except IndexError:
break
while True:
try:
request, async_object = self._queue.popleft()
if async_object:
async_object.set_exception(exc)
except IndexError:
break
def _safe_close(self):
self.handler.stop()
timeout = self._session_timeout // 1000
if timeout < 10:
timeout = 10
if not self._connection.stop(timeout):
raise WriterNotClosedException(
"Writer still open from prior connection "
"and wouldn't close after %s seconds" % timeout)
def _call(self, request, async_object):
"""Ensure there's an active connection and put the request in
the queue if there is.
Returns False if the call short circuits due to AUTH_FAILED,
CLOSED, EXPIRED_SESSION or CONNECTING state.
"""
if self._state == KeeperState.AUTH_FAILED:
async_object.set_exception(AuthFailedError())
return False
elif self._state == KeeperState.CLOSED:
async_object.set_exception(ConnectionClosedError(
"Connection has been closed"))
return False
elif self._state in (KeeperState.EXPIRED_SESSION,
KeeperState.CONNECTING):
async_object.set_exception(SessionExpiredError())
return False
self._queue.append((request, async_object))
示例2: KazooClient
# 需要導入模塊: from kazoo.protocol.connection import ConnectionHandler [as 別名]
# 或者: from kazoo.protocol.connection.ConnectionHandler import close [as 別名]
#.........這裏部分代碼省略.........
else:
log.info("Zookeeper connection lost")
# Connection lost
self._live.clear()
self._notify_pending(state)
self._make_state_change(KazooState.SUSPENDED)
def _notify_pending(self, state):
"""Used to clear a pending response queue and request queue
during connection drops."""
if state == KeeperState.AUTH_FAILED:
exc = AuthFailedError()
elif state == KeeperState.EXPIRED_SESSION:
exc = SessionExpiredError()
else:
exc = ConnectionLoss()
while True:
try:
request, async_object, xid = self._pending.popleft()
if async_object:
async_object.set_exception(exc)
except IndexError:
break
while True:
try:
request, async_object = self._queue.popleft()
if async_object:
async_object.set_exception(exc)
except IndexError:
break
def _safe_close(self):
self.handler.stop()
if not self._connection.stop(10):
raise Exception("Writer still open from prior connection"
" and wouldn't close after 10 seconds")
def _call(self, request, async_object):
"""Ensure there's an active connection and put the request in
the queue if there is."""
if self._state == KeeperState.AUTH_FAILED:
raise AuthFailedError()
elif self._state == KeeperState.CLOSED:
raise ConnectionClosedError("Connection has been closed")
elif self._state in (KeeperState.EXPIRED_SESSION,
KeeperState.CONNECTING):
raise SessionExpiredError()
self._queue.append((request, async_object))
# wake the connection, guarding against a race with close()
write_pipe = self._connection._write_pipe
if write_pipe is None:
raise ConnectionClosedError("Connection has been closed")
try:
os.write(write_pipe, b'\0')
except OSError as e:
if e.errno == errno.EBADF:
raise ConnectionClosedError("Connection has been closed")
raise
def start(self, timeout=15):
"""Initiate connection to ZK.
:param timeout: Time in seconds to wait for connection to