ngamsHighLevelLib.py 文件源码

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

项目:ngas 作者: ICRAR 项目源码 文件源码
def pingServer(host, port, timeout):
    """
    The function tries to ping (sends STATUS command) to the NG/AMS Server
    running on the given host using the given port number.
    """
    logger.debug("Pinging NG/AMS Server: %s:%d. Timeout: %.3f [s]", host, port, timeout)

    startTime = time.time()
    while True:
        try:
            resp = ngamsHttpUtils.httpGet(host, port, NGAMS_STATUS_CMD)
            with contextlib.closing(resp):
                if resp.status in (NGAMS_HTTP_SUCCESS, NGAMS_HTTP_UNAUTH):
                    logger.debug("Successfully pinged NG/AMS Server")
                    return
        except socket.error as e:
            if e.errno != errno.ECONNREFUSED:
                raise
            if (time.time() - startTime) >= timeout:
                break
            time.sleep(0.2)

    errMsg = "NGAS Server running on %s:%d did not respond within %.3f [s]"
    raise Exception(errMsg % (host, port, timeout))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号