Is there an upper limit to how long you can specify a thread to sleep with time.sleep()? I have been having issues with sleeping my script for long periods (i.e., over 1k seconds). This issue has appeared on both Windows and Unix platforms.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Actual answer, at least for my machine: 4294967.2950000003911900999... seconds.
OverflowError: sleep length is too large
The spec says:
Nothing about a time limit here. Certainly 1K seconds isn't much and should work without problems.
I suppose the longer the time the more probable situation described in the docs:
you can prevent possible issues by putting the sleep with short delay into the loop:
According to the documentation, time.sleep accepts any non-zero number [1], as you probably know. However you are under the influence of your operating systems scheduler as well [1].
[1] http://docs.python.org/library/time.html
Others have explained why you might sleep for less than you asked for, but didn't show you how to deal with this. If you need to make sure you sleep for at least n seconds you can use code like:
This may sleep more than n but it will never return before sleeping at least n seconds.