Python Forum
How to achieve close to 1ms time.sleep
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to achieve close to 1ms time.sleep
#1
Hi, I have a program that runs on both windows and Linux as a continuous thread with 1 millisecond interval, using time.sleep(0.001)

My programs seem to run slow on Windows than in Linux. After some finds, I noticed this:

"The time.sleep() function uses the underlying operating system's sleep() function. Ultimately there are limitations of this function. For example on a standard Windows installation, the smallest interval you may sleep is 10 - 13 milliseconds. The Linux kernels tend to have a higher tick rate, where the intervals are generally closer to 1 millisecond"

Is there any way to achieve the close to 1 milliseconds on Windows?

Please help me..

Thanks
kwekey
Reply
#2
exact timing is almost impossible without an event driven timer/counter especially on windows. That said,
this may be of interest: https://stackoverflow.com/a/11658115
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Use subprocess.Popen and time.sleep chucky831 2 1,890 Aug-11-2022, 07:53 PM
Last Post: carecavoador
  How to immediately kill and restart a thread while using a time.sleep() inside it? philipbergwerf 4 3,451 Feb-07-2022, 04:16 PM
Last Post: Gribouillis
  Time.sleep: stop appending item to the list if time is early quest 0 1,846 Apr-13-2021, 11:44 AM
Last Post: quest
  Can you end the Time.sleep function boier96 9 9,220 Jan-16-2021, 10:09 PM
Last Post: Serafim
  Is there a simplified way to achieve this Andrewbf 1 1,787 Jun-11-2020, 05:51 AM
Last Post: Yoriz
  time.sleep mtnwinds 4 2,795 May-21-2020, 10:12 AM
Last Post: Larz60+
  kill thread or process asap, even during time.sleep nanok66 4 2,867 Apr-29-2020, 10:13 AM
Last Post: nanok66
  time.sleep works erratically, a bug in Python? stipcevic 2 3,817 Jan-21-2020, 09:38 PM
Last Post: Marbelous
  Adding Cosinus as utime.sleep variable Kreszy 0 1,694 Sep-19-2019, 04:27 PM
Last Post: Kreszy
  Why does time.sleep(wait) add time in python3 ? gerardg 4 3,340 Apr-28-2019, 06:26 PM
Last Post: gerardg

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020