'Gracefully stop this Zookeeper session.
This method can be called while a reconnection attempt is in
progress, which will then be halted.
Once the connection is closed, its session becomes invalid. All
the ephemeral nodes in the ZooKeeper server associated with the
session will be removed. The watches left on those nodes (and
on their parents) will be triggered.'

def stop(self):

    if self._stopped.is_set():
        return
    self._stopped.set()
    self._queue.append((CloseInstance, None))
    os.write(self._connection._write_pipe, '\x00')
    self._safe_close()
