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)) # wake the connection, guarding against a race with close() write_pipe = self._connection._write_pipe if write_pipe is None: async_object.set_exception( ConnectionClosedError("Connection has been closed")) try: os.write(write_pipe, b'\0') except: async_object.set_exception( ConnectionClosedError("Connection has been closed"))
def _call(self, request, async_object): """Ensure there's an active connection and put the request in the queue if there is.""" with self._state_lock: 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.put((request, async_object))
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 testit(): raise ConnectionClosedError()
from kazoo.exceptions import ConnectionClosedError def zk_status_listener(state): if state == KazooState.LOST: print("Cleaned Working Tree.") # print("Session was lost") exit(0) elif state == KazooState.SUSPENDED: print("Handle being disconnected from Zookeeper") exit(0) try: zkr = KazooRetry(max_tries=-1) client = KazooClient(hosts="127.0.0.1:2181", connection_retry=zkr) client.add_listener(zk_status_listener) client.start() if client.exists("/servers"): client.delete("/servers", recursive=True) if client.exists("/mapping"): client.delete("/mapping", recursive=True) client.stop() client.close() except: raise ConnectionClosedError("Connection is closed") client.close() exit(0)