Python 中 time.sleep() 时出现奇怪的 IOError
Strange IOError when time.sleep() in Python
所以我在 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...
我可以修复它吗?我无法更改 spent 或 1.0101。
编辑:错误是:IOError: [Errno 22] Invalid argument.
EDIT2:我正在使用 Raspberry Pi 2.
在 Linux 中,将负数传递给 time.sleep
时通常会得到 IOError
。有些系统可能会永远休眠。
如果自 Python 3.3.
起提供负值,此 issue 已通过引发 ValueError
解决
所以我在 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...
我可以修复它吗?我无法更改 spent 或 1.0101。
编辑:错误是:IOError: [Errno 22] Invalid argument.
EDIT2:我正在使用 Raspberry Pi 2.
在 Linux 中,将负数传递给 time.sleep
时通常会得到 IOError
。有些系统可能会永远休眠。
如果自 Python 3.3.
起提供负值,此 issue 已通过引发ValueError
解决