Fast and Precise Python Repeating Timer

后端 未结 3 864
难免孤独
难免孤独 2021-01-12 14:39

I need to send repeating messages from a list quickly and precisely. One list needs to send the messages every 100ms, with a +/- 10ms window. I tried using the code below,

3条回答
  •  醉酒成梦
    2021-01-12 15:10

    Store the start time. Send the message. Get the end time. Calculate timeTaken=end-start. Convert to FP seconds. Sleep(0.1-timeTaken). Loop back.

提交回复
热议问题