check_local_network.py 文件源码

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

项目:xxNet 作者: drzorm 项目源码 文件源码
def _simple_check_worker():
    global _checking_lock, _checking_num, network_stat, last_check_time
    time_now = time.time()
    if config.PROXY_ENABLE:
        socket.socket = socks.socksocket
        xlog.debug("patch socks")

    _checking_lock.acquire()
    _checking_num += 1
    _checking_lock.release()

    network_ok = False
    for host in ["www.microsoft.com", "www.apple.com", "code.jquery.com", "cdn.bootcss.com", "cdnjs.cloudflare.com"]:
        if _check_one_host(host):
            network_ok = True
            break

    if network_ok:
        last_check_time = time.time()
        report_network_ok()
        xlog.debug("network is ok, cost:%d ms", 1000 * (time.time() - time_now))
    else:
        xlog.warn("network fail")
        network_stat = "Fail"
        last_check_time = time.time()

    _checking_lock.acquire()
    _checking_num -= 1
    _checking_lock.release()

    if config.PROXY_ENABLE:
        socket.socket = default_socket
        xlog.debug("restore socket")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号