time.sleep accuracy

Grant Edwards ge at nowhere.none
Tue Sep 19 16:50:36 CEST 2000

In article <39C6DA7B.2D19B1C1 at engcorp.com>, Peter Hansen wrote:
>Jonadab the Unsightly One wrote:
>> Nick Collier <nick at src.uchicago.edu> wrote:
>> > I'm wondering if anyone knows how accurate time.sleep is? For example,
>> > if I want to sleep for 50 milliseconds (time.sleep(.05)), what's the
>> > actual margin or error? Is this os dependent?

On most Unix systems, the process will sleep for at least 50ms.
There is no upper bound.  If it's a low priority task on a
heavily loaded system, it may not wake up for quite some time.

>> In theory, it's hardware dependant.  But reasonably modern
>> hardware should be able to get within a millisecond if the
>> software is sufficiently discerning, so in practice it
>> probably is not hardware dependent on modern systems.
>Is the latter statement more than just theory?  I strongly doubt that
>Windows, for example, would consistently come in any closer than +/- ten
>or twenty milliseconds.  Maybe on a real-time operating system.

The clock tick on most of the Unix systems I've used was 10ms,
so if time.sleep() really does put a process to sleep rather
than doing a busy-wait, the granularity is going to be 10ms.

Grant Edwards                   grante             Yow!  I'm ZIPPY!! Are we
                                  at               having FUN yet??

More information about the Python-list mailing list