connectors.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:ghpythonremote 作者: Digital-Structures 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号