Sleep for exact time in python

Because you’re working with a preemptive operating system, there’s no way you can guarantee that your process will be able to have control of the CPU in 25ms.

If you’d still like to try, it would be better to have a busy loop that polls until 25ms has passed. Something like this might work:

import time
target_time = time.clock() + 0.025
while time.clock() < target_time:
    pass

Leave a Comment