def connect(self): if self._connected: logging.warning("Bridge already connected!") return self._server.start() # Get ACK from peer msg = tws_pb.ConnectRequest(app_id=self._app_id, worker_rank=self._rank, identifier=self._identifier) self._rpc_with_retry( lambda: self._client.Connect(msg), "Bridge failed to connect") logging.debug('Has connected to peer.') # Ensure REQ from peer with self._condition: while not self._connected: self._condition.wait() logging.debug('Connected from peer.') if self._streaming_mode: logging.debug('enter streaming_mode.') self._client_daemon = threading.Thread( target=self._client_daemon_fn) self._client_daemon.start() logging.debug('finish connect.')
def connect(self): if self._connected: logging.warning("Bridge already connected!") return self._server.start() # Get ACK from peer msg = tws_pb.ConnectRequest(app_id=self._app_id, worker_rank=self._rank, identifier=self._identifier) while True: try: self._client.Connect(msg) except Exception as e: # pylint: disable=broad-except logging.warning("Bridge failed to connect: %s. " \ "Retry in 1 second...", repr(e)) time.sleep(1) continue break logging.debug('Has connected to peer.') # Ensure REQ from peer with self._condition: while not self._connected: self._condition.wait() logging.debug('Connected from peer.') if self._streaming_mode: logging.debug('enter streaming_mode.') self._client_daemon = threading.Thread( target=self._client_daemon_fn) self._client_daemon.start() logging.debug('finish connect.')
def connect(self): if self._role == 'leader': assert not self._connected, "Already connected" msg = tws_pb.ConnectRequest(app_id=self._app_id, worker_rank=self._rank) while True: try: self._client.Connect(msg) except Exception as e: # pylint: disable=broad-except logging.warning("Bridge failed to connect: %s. " \ "Retry in 1 second...", e.code().name) time.sleep(1) continue break self._connected = True logging.debug('Bridge connected as leader') else: with self._condition: while not self._connected: self._condition.wait() logging.debug('Bridge connected as follower') if self._streaming_mode: self._client_daemon = threading.Thread( target=self._client_daemon_fn) self._client_daemon.start()