Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)
I want to wait for about 25ms in one of my functions. Here and there this capacity is considered when the processor is busy with different things and different occasions it has the processor all to itself.

I've attempted time.sleep(.25) however at times its really 25ms and different occasions it takes any longer. Is there an approach to rest for a definite measure of time regardless to processor accessibility?

1 Answer

0 votes
by (26.4k points)

Since you're working with a preemptive OS, it is highly unlikely you can ensure that your process will actually want to have control of the CPU in 25ms. 

In the event that you'd in any case prefer to attempt, it is smarter to have a busy loop that surveys until 25ms has passed. Something like this may work:

import time

target_time = time.clock() + 0.025

while time.clock() < target_time:

    pass

Wanna become a Python expert? Come and join the python certification course and get certified.

Related questions

0 votes
1 answer
+2 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...