So I have a pretty strange error when using time.sleep() in Python.
start = time.time()
# some code goes here
end = time.time()
spent = end - start
time.sleep(1.0101 - spent) # this gives a strange IOError...
Can I fix it? I can't change spent or 1.0101.
EDIT: The error is: IOError: [Errno 22] Invalid argument.
EDIT2: I'm using a Raspberry Pi 2.
In Linux you usually get IOError
when passing a negative number to time.sleep
. Some systems may sleep forever instead.
This issue has been resolved by raising a ValueError
if a negative value is provided since Python 3.3.