Python:高精度 time.sleep [英] Python: high precision time.sleep

查看:84
本文介绍了Python:高精度 time.sleep的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能告诉我如何在 Win32 和 Linux 上的 Python2.6 中获得高精度的睡眠函数吗?

can you tell me how can I get a high precision sleep-function in Python2.6 on Win32 and on Linux?

推荐答案

您可以在 sleep():

参数可能是一个浮点数,以表示更精确的睡眠时间.

The argument may be a floating point number to indicate a more precise sleep time.

所以

time.sleep(0.5)

会睡半秒.

然而,在实践中,您不太可能获得超过毫秒级的睡眠精度,因为操作系统通常只支持毫秒级睡眠,而且很短的时间很快就会变得不可靠.

In practice, however, it's unlikely that you will get much more than millisecond precision with sleep because operating systems usually only support millisecond sleeps and because very short amounts of time quickly get unreliable.

这篇关于Python:高精度 time.sleep的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆