Python 中的 time.sleep() 时出现奇怪的 IOError

Ace*_*Ace 1 python ioerror

所以在 Python 中使用 time.sleep() 时我有一个非常奇怪的错误。

start = time.time()
# some code goes here
end = time.time()
spent = end - start
time.sleep(1.0101 - spent) # this gives a strange IOError...
Run Code Online (Sandbox Code Playgroud)

我可以修吗?我无法更改已用或 1.0101。
编辑:错误是:IOError: [Errno 22] 无效参数。
EDIT2:我使用的是 Raspberry Pi 2。

cdo*_*nts 5

在 Linux 中,您通常IOError在将负数传递给time.sleep. 有些系统可能会永远休眠。

如果自 Python 3.3 起提供负值,则已通过提高 a 来解决此问题ValueError

  • 谢谢。结果是否定的。 (2认同)