繁体   English   中英

使用时间获取 ping 总是返回更高的毫秒?

[英]Getting ping using time always returns a higher ms?

我正在尝试使用 python 检查我的机器的 ping,但使用 time.time() 的结果总是大于从 subprocess.call(['ping', param, '1',主持人])。 为什么是这样? 我怎么能只解析来自子进程调用的 ping 呢?

def ping():
global performanceScore

host = '8.8.8.8'
param = '-n' if platform.system().lower()=='windows' else '-c'
command = ['ping', param, '1', host]

start = time.time()
result = subprocess.call(command)

pingTime = time.time() - start
pingTime *= 1000
#round(pingTime, 2)
print('ping: ', pingTime, 'ms')

if pingTime < 80:
    performanceScore += 1
else:
    performanceScore = 0

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM