def _handle_attempt(self): """ This method is called when the socket is not connected, once every loop of the IOManager. """ self.handle_loop_disconnected() if time.time() < self.__last_attempt + self.__timeout: return False self.__last_attempt = time.time() if self.__listener: result = self.__listen() else: result = self.__connect() if not result: self.__attempt += 1 action = "bind to port" if self.__listener else "connect" if self.__giveup >= 0 and self.__attempt >= self.__giveup: self.__logger.critical("Failed to %s for %d times. Giving up." \ % (action, self.__attempt)) mgr = IOManager() mgr.unregister_unconnected(self) elif self.__giveup >= 0: self.__logger.critical("Failed to %s for %d/%d times. " \ "Retrying in %d seconds." \ % (action, self.__attempt, \ self.__giveup, self.__timeout)) else: self.__logger.critical("Failed to %s for %d times. " \ "Retrying in %d seconds." \ % (action, self.__attempt, \ self.__timeout)) else: self.__attempt = 0
def _handle_attempt(self): """ This method is called when the socket is not connected, once every loop of the IOManager. """ self.handle_loop_disconnected() if time.time() < self.__last_attempt + self.__timeout: return False self.__last_attempt = time.time() if self.__listener: result = self.__listen() else: result = self.__connect() if not result: self.__attempt += 1 action = "bind to port" if self.__listener else "connect" if self.__giveup >= 0 and self.__attempt >= self.__giveup: self.__logger.critical("Failed to %s for %d times. Giving up." \ % (action, self.__attempt)) mgr = IOManager() mgr.unregister_unconnected(self) elif self.__giveup >= 0: self.__logger.critical("Failed to %s for %d/%d times. " \ "Retrying in %d seconds." \ % (action, self.__attempt, \ self.__giveup, self.__timeout)) else: self.__logger.critical("Failed to %s for %d times. " \ "Retrying in %d seconds." \ % (action, self.__attempt, \ self.__timeout)) else: self.__attempt = 0