首页 > 解决方案 > 快速检测本地网络路径

问题描述

Python有没有办法快速检测本地网络路径的存在?

我试过使用os.path.existsand urllib2.urlopen。当路径不存在时,它们至少需要几十秒的时间来检测路径是否存在。

有没有可能把时间缩短到十秒以内?

这是我的测试代码:

# -*- coding: utf-8 -*-

import os
import sys
from urllib2 import urlopen

path = "file:////192.168.199.249/Users"
try:
    urlopen(path, timeout=1)
    print "exist"
except Exception, e:
    print "not exist"

if os.path.exists(path):
    print "exist"
else:
    print "not exist"

标签: pythonurllib2

解决方案


推荐阅读