Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange IOError when time.sleep() in Python

Tags:

python

ioerror

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.

like image 687
Ace Avatar asked May 30 '26 19:05

Ace


1 Answers

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.

like image 64
cdonts Avatar answered Jun 02 '26 10:06

cdonts