def _get_connection(self):
connection = None
logger.info("Connecting...")
for i in range(self.timeout):
try:
if not connection:
logger.debug("Connecting. Timeout in {:d} seconds.".format(self.timeout - i))
connection = rpyc.classic.connect('localhost', self.port)
else:
logger.debug("Found connection, testing. Timeout in {:d} seconds.".format(self.timeout - i))
connection.ping(timeout=1)
logger.debug("Connection ok, returning.")
logger.info("Connected.")
return connection
except (socket.error, rpyc.core.protocol.PingError, rpyc.core.async.AsyncResultTimeout) as e:
if e is socket.error and not e.errno == errno.ECONNREFUSED:
raise
if i == self.timeout - 1:
raise
elif e is socket.error:
sleep(1)
评论列表
文章目录